Colony binding crash

Branch: Current, master. (b4a97d1ba689e549f1a33e9afa1d0eb3907c10d4)

I’m not sure if this is a duplicate on Github so I post it here.

Happens by chance when:

  1. Develop a rather large colony. (You can achieve this by check Infinite Compound, bind then unbind)
  2. Find a group of bacteria with Pilus
  3. Try to engulf them

Some cells in your colony will die, and by chance some cells will be removed from your colony and form their own (I don’t know why), and chances are when forming, one happens to die.

This one happens when binding.
An invoke target is already disposed

And this one when removing.
Cannot access a disposed object

This time the game doesn’t crash but stops functioning normally. (Edit: now it crashed)
An invoke target is already disposed

My very first thought is that the colony got split in two with an indermediate cell dying, like:

p - c - c - c => p - x - c - c => p // c-c

With p the player cell, c alive cells, x dead cells. As cases of voluntary unbinding are normally covered, I can’t affirm this for sure though.

I don’t know how this can relate to the subsequent crash, but given that we mostly have player controlled colonies, we may have missed some bugs.

I’ve seen code that any cell leaving the colony (either due to death or otherwise) will first detach all cells connected to them, so the cells that would be in the “detached” chain should have been kicked out of the colony. I’ve tested this multiple times with 3 cell colony where I intentionally killed the middle cell with a floating toxin and that worked as expected.

Well, to reproduce this bug, you need a rather large colony. (Maybe 10+ cells) A cell in the middle is killed, so the colony splits into two (Edit: Maybe not? I don’t really know the reason for the following crash)

Append:

I’m having this disposed RigidBody in my colony. I don’t know where it is disposed, but the truth is that the game keeps crashing.

Some recordings are at:

Okay so it looks like hostileEngulfer variable refers to a disposed microbe. I think we may be able to fix this by either making it so that the current microbe detects that the hostileEngulfer is gone (maybe with a physics callback or a just flatout object disposed check here, which I wouldn’t prefer) or the alternative is that the hostileEngulfer microbe when it is destroyed notifies any microbe it is engulfing that it is going to be destroyed.