run mark and sweep on a think hook

This commit is contained in:
Ayane Satomi 2022-08-02 00:19:15 +08:00
parent 97fa187f65
commit bf6fe6ef91
No known key found for this signature in database
GPG key ID: 431E3C36BEBE204B

View file

@ -48,7 +48,6 @@ end
function cleanupInvalid(t, v)
for i, sv in ipairs(t) do
if not isValid(sv.this) then
print("WARNING: " .. tostring(sv.this) .. " is no longer valid but exists in table.")
table.remove(t, i)
end
end
@ -101,15 +100,16 @@ if CLIENT then
end
end)
timer.create("cleanup_invalid", 0.8, 0, function()
cleanupInvalid(serverMetadata.runningChips)
end)
-- update the running chip entries when necessary
timer.create("update_data", 5, 0, function()
getRunningChips()
end)
-- mark and sweep invalid entries
hook.add("think", "dispose_object", function()
cleanupInvalid(serverMetadata.runningChips)
end)
hook.add("render", "metadataRenderMain", function()
render.setColor(Color(255, 34, 34))
render.drawText(10, 10, "Server Name: " .. serverMetadata.serverName)