From 2aafe1b6b60d8bfa61c9be5fa02138b9f9135b19 Mon Sep 17 00:00:00 2001 From: TwistedTail <8784231+TwistedTail@users.noreply.github.com> Date: Sun, 23 Jun 2024 03:51:14 -0400 Subject: [PATCH 1/3] Added a connection check before attempting to disconnect - CFW.disconnect will now actually check if both entities are connected before doing anything. --- lua/cfw/core/connectivity_sv.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lua/cfw/core/connectivity_sv.lua b/lua/cfw/core/connectivity_sv.lua index 5742450..2f1a8ea 100644 --- a/lua/cfw/core/connectivity_sv.lua +++ b/lua/cfw/core/connectivity_sv.lua @@ -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 From 0a31f7e20c080f3ec93819b13a9338e605b2068c Mon Sep 17 00:00:00 2001 From: TwistedTail <8784231+TwistedTail@users.noreply.github.com> Date: Sun, 23 Jun 2024 03:52:18 -0400 Subject: [PATCH 2/3] Added an extra check to ENT:GetLinks() - 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. --- lua/cfw/classes/link_sv.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lua/cfw/classes/link_sv.lua b/lua/cfw/classes/link_sv.lua index 32e1d87..6f2142a 100644 --- a/lua/cfw/classes/link_sv.lua +++ b/lua/cfw/classes/link_sv.lua @@ -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 From 1f818733f83e721995daad2c1301b8cf64a272f9 Mon Sep 17 00:00:00 2001 From: TwistedTail <8784231+TwistedTail@users.noreply.github.com> Date: Sun, 23 Jun 2024 03:52:43 -0400 Subject: [PATCH 3/3] Fixed annoying missing ENT._links table error --- lua/cfw/core/connectivity_sv.lua | 2 +- lua/cfw/core/parenting_sv.lua | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lua/cfw/core/connectivity_sv.lua b/lua/cfw/core/connectivity_sv.lua index 2f1a8ea..971cc95 100644 --- a/lua/cfw/core/connectivity_sv.lua +++ b/lua/cfw/core/connectivity_sv.lua @@ -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 diff --git a/lua/cfw/core/parenting_sv.lua b/lua/cfw/core/parenting_sv.lua index c38952b..59c2ca2 100644 --- a/lua/cfw/core/parenting_sv.lua +++ b/lua/cfw/core/parenting_sv.lua @@ -92,4 +92,18 @@ hook.Add("Initialize", "CFW", function() end) hook.Remove("Initialize", "CFW") -end) \ No newline at end of file +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)