Why not drop invulnerability entirely since that seems to be where the bug stems and just give the heart(s) more HP. Simple solution.