IDs recalc clear flag was accessing freed memory. There is more detailed comment about solution in the code.