From 9a5181b61415d46670abdcac7ae8acc0f6d4b58e Mon Sep 17 00:00:00 2001 From: LengthenedGradient <109800352+LengthenedGradient@users.noreply.github.com> Date: Tue, 23 Jun 2026 21:36:15 -0400 Subject: [PATCH] Fix proper clipping compatibility? I love race conditions --- lua/primitive/entities/base.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lua/primitive/entities/base.lua b/lua/primitive/entities/base.lua index 6fe49c3..1028648 100644 --- a/lua/primitive/entities/base.lua +++ b/lua/primitive/entities/base.lua @@ -621,6 +621,28 @@ do end end) + -- Re-apply any proper_clipping physics clips after each primitive reconstruction. + -- Primitives reinitialize via PhysicsInitMultiConvex on every reconstruction, which wipes the clips + -- Bypass the race condition by preserving existing clips on rebuild + hook.Add("Primitive_PostRebuildPhysics", "Primitive_ProperClipping", function( ent ) + if not ent.Clipped or not istable( ent.ClipData ) then return end -- no clips to reapply + if not ProperClipping or not isfunction( ProperClipping.ClipPhysics ) then return end -- proper_clipping not installed + + -- Aggregate all physics clips + local norms, dists = {}, {} + local count = 0 + for _, clip in ipairs( ent.ClipData ) do + if clip.physics then + count = count + 1 + norms[count] = clip.norm + dists[count] = clip.dist + end + end + + if count == 0 then return end -- no physics clips to reapply + + ProperClipping.ClipPhysics( ent, norms, dists, true ) + end) end