Skip to content

Commit b34d6c0

Browse files
authored
Try to fix NULLs in E2Lib.PlayerChips (#3571)
* Try to fix NULL errors * Change it here too just in case
1 parent f1aed5b commit b34d6c0

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lua/entities/gmod_wire_expression2/core/core.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,11 @@ e2function number totalCpuUsage()
217217
local owner = self.player
218218
if not IsValid(owner) then return self.timebench end
219219

220-
return E2Lib.PlayerChips[owner]:getTotalTime()
220+
-- To avoid creating new table
221+
local chips = rawget(E2Lib.PlayerChips, owner)
222+
if not chips then return self.timebench end
223+
224+
return chips:getTotalTime()
221225
end
222226

223227
[nodiscard]

lua/entities/gmod_wire_expression2/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,9 @@ function ENT:OnRemove()
392392
end
393393

394394
local owner = self.player
395+
local chips = rawget(E2Lib.PlayerChips, owner)
395396

396-
if IsValid(owner) then
397-
local chips = E2Lib.PlayerChips[owner]
397+
if chips then
398398
chips:remove(self)
399399

400400
if #chips == 0 then

0 commit comments

Comments
 (0)