Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This was actually a really annoying issue to deal with, I'll explain everything I found out about it and the way I dealt with it. For starters, this error was showing up in multiple different ways, may it be because of a NULL entity or a point entity, but ultimately it was related to an entity missing a table:
So I went onto checking at what point these entities were getting connected to the contraption, after all we're dealing with constraints here and you never know what Gmod could give you, with no avail. This led me to check the links of the source entity that was being disconnected and then floodfilled.
Just then, I noticed the source entity's links were flooded with NULL entities, hundreds of them in one of the many debug prints I got, that were inferfering, so now a race condition was on the table. It still didn't explain stuff like the debris and flames being attached to the contraption, after all they're just stuff that gets thrown around when something explodes.
After adding more and more information to the link table debug, I finally noticed what was happening.
Entity [125][entityflame] prop_physics[125] gmod_wire_gate[117]
So here's the trouble with this snippet: Our first entity, the flame, is called using the ID stored by the link, and the next two are the classes and ID of the entities that were originally stored on that specific link. What was originally the ID of a prop is now the ID of the flame entity.
This means we were not only dealing with one race condition but TWO race conditions, one for the many entities being removed too quickly and another for entities being spawned and using the IDs of these entities as soon as they're removed.
My solution was to simply hook onto
EntityRemoved
and disconnect all the entities linked to the one being deleted, after 30 solid minutes of blowing up my test vehicle I wasn't able to replicate the issue again. Even though a whole 100 dupes didn't create a single error, I highly recommend more people to test this fix.