From fc8c6ad38a82a5a845eab95b14763194a2d43ada Mon Sep 17 00:00:00 2001 From: Rip Rip Rip <140695311+Rip-Rip-Rip@users.noreply.github.com> Date: Fri, 29 May 2026 02:45:08 +0100 Subject: [PATCH] Fixed various LBL crashes. - Added a cap to the maximum number of lit bridge entities to prevent linked list overflow related crashes. - Fixed a crash which could occur when repeatedly enabling and disabling bridges. --- .../scripts/vscripts/light_bridge_lights/helper.nut | 6 ++++++ light_bridge_lights/scripts/vscripts/sv_init.nut | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/light_bridge_lights/scripts/vscripts/light_bridge_lights/helper.nut b/light_bridge_lights/scripts/vscripts/light_bridge_lights/helper.nut index 2393184..c3f698e 100644 --- a/light_bridge_lights/scripts/vscripts/light_bridge_lights/helper.nut +++ b/light_bridge_lights/scripts/vscripts/light_bridge_lights/helper.nut @@ -17,5 +17,11 @@ if(!("LBL_Dev" in getroottable())) { function distance(vec1, vec2) { return (vec1 - vec2).Length() } + + function numOfItemsInTable(table) { + local count = 0 + foreach(item in table) count++ + return count + } } } \ No newline at end of file diff --git a/light_bridge_lights/scripts/vscripts/sv_init.nut b/light_bridge_lights/scripts/vscripts/sv_init.nut index 994c1bd..2980874 100644 --- a/light_bridge_lights/scripts/vscripts/sv_init.nut +++ b/light_bridge_lights/scripts/vscripts/sv_init.nut @@ -21,6 +21,7 @@ const LBL_LIGHT_VOLUMETRIC_DENSITY = 0.025 const LBL_LIGHT_SPACING = 24 // distance between lights in units, less spacing means more lights but a higher performance cost const LBL_LIGHT_MAXCOUNT = 128 // maximum number of lights per bridge to prevent performance issues +const LBL_MAX_NUMBER_OF_LIT_BRIDGES = 4 // max number of bridges that can have lights at once, having too many could cause a crash depending on the length of the bridges (due to the increased number of lights) const LBL_LIGHT_SPECIFIC_HEALTH = 27852 // used to identify lights created by this script @@ -99,7 +100,7 @@ function LBL_bridgeCacheRefresh() { if(!bridge.IsValid()) { LBL_lightRemoveAtBridge(bridgeIndex) LBL_bridgesCacheMarkedForReset = true // wait until next tick to prevent crashes - break + return } local lightCountNew = LBL_bridgeGetLightCount(bridge) @@ -116,7 +117,7 @@ function LBL_bridgeCacheRefresh() { } for(local bridge = null; bridge = Entities.FindByClassname(bridge, "projected_wall_entity");) { - if(LBL_bridgeIsCached(bridge) || !bridge.IsValid()) continue // skip cached bridges or invalid bridges + if(LBL_bridgeIsCached(bridge) || !bridge.IsValid() || LBL_Dev.numOfItemsInTable(LBL_bridgesCached) >= LBL_MAX_NUMBER_OF_LIT_BRIDGES) continue // skip cached bridges or invalid bridges, and prevent too many lit bridges to prevent crashes // update cache with new bridge