Skip to content

Commit

Permalink
Another possible fix related to #183
Browse files Browse the repository at this point in the history
There was a memory leak when using the graphical debug display.

- Now explicitly delete any created object nodes before clearing the objects to unload table
- Also only refresh the object array every 200ms to improve performance without much noticeable delay
  • Loading branch information
loki79uk committed Dec 1, 2023
1 parent cc40d5b commit 607d044
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions UniversalAutoload.lua
Expand Up @@ -3094,7 +3094,12 @@ end
function UniversalAutoload.buildObjectsToUnloadTable(vehicle, forceUnloadPosition)
local spec = vehicle.spec_universalAutoload

spec.objectsToUnload = {}
spec.objectsToUnload = spec.objectsToUnload or {}
for k, v in pairs(spec.objectsToUnload) do
delete(v.node)
spec.objectsToUnload[k] = nil
end

spec.unloadingAreaClear = true


Expand Down Expand Up @@ -5254,7 +5259,12 @@ function UniversalAutoload:drawDebugDisplay(isActiveForInput)
end
end

UniversalAutoload.buildObjectsToUnloadTable(self)
UniversalAutoload.debugRefreshTime = (UniversalAutoload.debugRefreshTime or 0) + g_currentDt
if spec.objectsToUnload == nil or UniversalAutoload.debugRefreshTime > UniversalAutoload.delayTime then
UniversalAutoload.debugRefreshTime = 0
UniversalAutoload.buildObjectsToUnloadTable(self)
end

for object, unloadPlace in pairs(spec.objectsToUnload) do
local containerType = UniversalAutoload.getContainerType(object)
local w, h, l = UniversalAutoload.getContainerDimensions(object)
Expand Down
2 changes: 1 addition & 1 deletion modDesc.xml
Expand Up @@ -2,7 +2,7 @@
<modDesc descVersion="79">

<author>loki_79</author>
<version>1.4.4.0</version>
<version>1.4.5.0</version>

<title>
<en>Universal Autoload</en>
Expand Down

0 comments on commit 607d044

Please sign in to comment.