Issues related to despawning

I was messing around in my own fork of Thrive and came across four issues related to despawning. They are kind of related so I just put them all in this thread. As far as I can tell, my fork doesn’t cause these issues. I do have changes in my fork that make observing these issues easier, like printing the amount of living cells in the console or changing spawning radius to better see spawning and despawning. I can provide more details if wanted.

  1. Despawning entities takes a long time and doesn’t keep up with spawning. Despawning only happens about once a second. This means that over time the amount of living cells can climb to over 100, and it usually doesn’t really decrease from that even after dying. This causes a lot of lag.
    One simple fix is to raise Constants.MAX_DESPAWNS_PER_FRAME from 1 to 100. That makes it so dying or just swimming to another area actually successfully despawns entities so they drop below 10 in a couple of seconds and your fps goes back to normal. You can also make the max despawns per frame 10 if you’re worried about issue (4). That still despawns cells pretty fast but not as fast. I think 100 is good, though.

  2. Cells can spawn outside the despawn radius. This is because the despawn radius is equal to the spawning radius, which means that parts of bacterial colonies can reach outside the radius. This is especially important after fixing issue (1) because it makes those cells despawn instantly.
    This can be fixed by adding a bigger despawn radius, for example spawning radius + 50 = 220.

  3. Enemy cells spawned by cheats don’t despawn at all.
    This can be fixed by using the method AddEntityToTracked.

  4. A massive pile of entities despawning very fast can crash the game. I could only reproduce this while stress testing my fork by using cheats to spawn a massive ball of cells and then dying or migrating. I think this is impossible to reproduce without cheats, so this is probably very low priority. I don’t have a fix for this.

Should I make proper issues on Github? Oh and by the way, if my simple fixes sound good then I guess could make a pull request for them.

6 Likes

If these are accurate these are very good and important findings. I’ll try out the easier fixes tomorrow. The despawning not working fast enough would be a huge breakthrough if that is the case. I think I’ll try upping the despawns per frame a bit and making sure the despawning logic runs maybe about 10-20 times per second.

Most of the crashes in the game (some public reports here: ThriveDevCenter) seem to be memory corruption issues, and always hit in either mono or physics stacktraces. I have a guess that the Godot bullet integration is the primary culprit here as I’d hope that if such serious bugs were in mono they would have been fixed already. I guess that’s one more reason why the Godot devs are throwing in the towel and entirely removing bullet in 4.0.

I’d appreciate if you could make a PR. Maybe start with issue 3 as that should be very simple and easily get through the review process. Changing 2 needs to put the extra radius in Constants.cs so that is a tiny bit more difficult to fix.

I’ve now started working on this:

Update: I think I’ve done 1 and 2 now. I just need to test a bit more before asking for reviews on my PR.

1 Like

Cool, I’ll take a look.