This fix is correct I think.
If I guess correctly (I didn't check the code), the problem is that calling
erase(i) on an interaction is not erasing immediatly. Instead it sends a
message to the collider to erase "i" at next step. If you save, the next
step never comes and junk interactions are saved.
An alternative fix would be to check bodies before saving (if b1 or b2 does
not exist, don't save). I'm not sure it would be better, but it would be
more complicated probably.
This fix is correct I think.
If I guess correctly (I didn't check the code), the problem is that calling
erase(i) on an interaction is not erasing immediatly. Instead it sends a
message to the collider to erase "i" at next step. If you save, the next
step never comes and junk interactions are saved.
An alternative fix would be to check bodies before saving (if b1 or b2 does
not exist, don't save). I'm not sure it would be better, but it would be
more complicated probably.