Skip to content

Commit 9fc53b9

Browse files
Rip-Rip-Ripozxybox
authored andcommitted
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.
1 parent e30730a commit 9fc53b9

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

light_bridge_lights/scripts/vscripts/light_bridge_lights/helper.nut

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,11 @@ if(!("LBL_Dev" in getroottable())) {
1717
function distance(vec1, vec2) {
1818
return (vec1 - vec2).Length()
1919
}
20+
21+
function numOfItemsInTable(table) {
22+
local count = 0
23+
foreach(item in table) count++
24+
return count
25+
}
2026
}
2127
}

light_bridge_lights/scripts/vscripts/sv_init.nut

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const LBL_LIGHT_VOLUMETRIC_DENSITY = 0.025
2121

2222
const LBL_LIGHT_SPACING = 24 // distance between lights in units, less spacing means more lights but a higher performance cost
2323
const LBL_LIGHT_MAXCOUNT = 128 // maximum number of lights per bridge to prevent performance issues
24+
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)
2425

2526
const LBL_LIGHT_SPECIFIC_HEALTH = 27852 // used to identify lights created by this script
2627

@@ -99,7 +100,7 @@ function LBL_bridgeCacheRefresh() {
99100
if(!bridge.IsValid()) {
100101
LBL_lightRemoveAtBridge(bridgeIndex)
101102
LBL_bridgesCacheMarkedForReset = true // wait until next tick to prevent crashes
102-
break
103+
return
103104
}
104105

105106
local lightCountNew = LBL_bridgeGetLightCount(bridge)
@@ -116,7 +117,7 @@ function LBL_bridgeCacheRefresh() {
116117
}
117118

118119
for(local bridge = null; bridge = Entities.FindByClassname(bridge, "projected_wall_entity");) {
119-
if(LBL_bridgeIsCached(bridge) || !bridge.IsValid()) continue // skip cached bridges or invalid bridges
120+
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
120121

121122
// update cache with new bridge
122123

0 commit comments

Comments
 (0)