Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed missing ENT._links error #9

Merged
merged 3 commits into from
Jun 28, 2024
Merged

Fixed missing ENT._links error #9

merged 3 commits into from
Jun 28, 2024

Conversation

TwistedTail
Copy link
Member

@TwistedTail TwistedTail commented Jun 23, 2024

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:

[NULL Entity]
Entity [124][acf_debris]
Entity [196][entityflame]
Weapon [154][acf_torch] -- Genuinely concerned how this one happened

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.

- CFW.disconnect will now actually check if both entities are connected before doing anything.
- In some cases, you could use ENT:GetLinks() on entities that were never linked before, now we'll make sure that's the case before copying that table.
@brandonsturgeon
Copy link

🎉

Applied to CFC, will let you know how it goes 👍

@brandonsturgeon
Copy link

Haven't seen the error (or anything related) since we swapped to this branch. I also haven't received any complaints about malfunctions or bugs, so I'd say this is solid 👍

@TwistedTail TwistedTail merged commit c1a3823 into ACF-Team:main Jun 28, 2024
1 check passed
@TwistedTail TwistedTail deleted the fix-links-error branch June 28, 2024 06:11
@bluemetaknight
Copy link

Having this issue when parenting starfall holograms to a contraption.

`[cfw] addons/cfw/lua/cfw/core/connectivity_sv.lua:68: attempt to index field '_links' (a nil value)

  1. disconnect - addons/cfw/lua/cfw/core/connectivity_sv.lua:68
  2. SetParent - addons/cfw/lua/cfw/core/parenting_sv.lua:63
    3. unknown - addons/starfallex/lua/entities/starfall_hologram/cl_init.lua:23 (x12)

[cfw] addons/cfw/lua/cfw/classes/link_sv.lua:72: attempt to index a nil value

  1. Sub - addons/cfw/lua/cfw/classes/link_sv.lua:72
  2. disconnect - addons/cfw/lua/cfw/core/connectivity_sv.lua:72
    3. fn - addons/cfw/lua/cfw/core/parenting_sv.lua:107
    4. unknown - lua/ulib/shared/hook.lua:109 (x6)
    `

@bluemetaknight
Copy link

Having done some testing, it seems to happen only when creating holograms and parenting them in the same tick. Delaying parenting till next tick seems to resolve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants