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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lua/cfw/classes/link_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,13 @@ do
end

function ENT:GetLinks() -- Creates a shallow copy of the links table
local out = {}
local links = self._links
local out = {}

for k, v in pairs(self._links) do
out[k] = v
if links then
for k, v in pairs(links) do
out[k] = v
end
end

return out
Expand Down
7 changes: 5 additions & 2 deletions lua/cfw/core/connectivity_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local function floodFill(source, sinkIndex)

if entIndex == sinkIndex then return true, closed end

for neighborIndex, _ in pairs(Entity(entIndex)._links) do -- neighborIndex, neighborLink
for neighborIndex in pairs(Entity(entIndex)._links) do -- neighborIndex, neighborLink
if not closed[neighborIndex] then
open[neighborIndex] = true
end
Expand Down Expand Up @@ -65,7 +65,10 @@ end
function CFW.disconnect(entA, indexB)
if entA:EntIndex() == indexB then return end -- Should not happen normally, but ragdolls allow you to constrain to other bones on the same ragdoll, and it is the same entity

local link = entA._links[indexB]
local link = entA._links[indexB]

if not link then return end -- There's nothing to disconnect here

local contraptionPopped = link:Sub()

if contraptionPopped then return end
Expand Down
16 changes: 15 additions & 1 deletion lua/cfw/core/parenting_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,18 @@ hook.Add("Initialize", "CFW", function()
end)

hook.Remove("Initialize", "CFW")
end)
end)

-- In order to prevent NULL entities flooding the ENT._links table, we'll just get rid of them before they get removed
-- This is a fix for a really annoying issue that was showing up in multiple different ways
hook.Add("EntityRemoved", "cfw.entityRemoved", function(ent)
if not IsValid(ent) then return end

local links = ent:GetLinks()

if not links then return end

for index in pairs(links) do
disconnect(ent, index)
end
end)