Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clear-smoke memory leaks #1203

Merged
merged 6 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Template for new versions:
- `quickfort`: allow farm plots to be built on muddy stone
- `suspend`: remove broken ``--onlyblocking`` option; restore functionality to ``suspend all``
- `gui/create-item`: allow creation of adamantine thread, wool, and yarn
- `clear-smoke`: fix memory leak caused by the smoke flow not being deleted from memory

## Misc Improvements
- `gui/launcher`: "space space to toggle pause" behavior is skipped if the game was paused when `gui/launcher` came up to prevent accidental unpausing
Expand Down
31 changes: 17 additions & 14 deletions clear-smoke.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
-- Removes all smoke from the map

--[====[

clear-smoke
===========

Removes all smoke from the map. Note that this can leak memory and should be
used sparingly.

]====]
local flows_to_delete = {}

function clearSmoke(flows)
local success
for i = #flows - 1, 0, -1 do
if flows[i].type == df.flow_type.Smoke then
local flow = flows[i]
if flow.type == df.flow_type.Smoke then
flows:erase(i)
flows_to_delete[flow] = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can't this be deleted inline? other tools successfully do it that way, e.g. https://github.com/DFHack/dfhack/blob/develop/plugins/lua/dwarfvet.lua#L129-L137

success = true
end
end
return success
end

clearSmoke(df.global.flows)

for _, block in pairs(df.global.world.map.map_blocks) do
clearSmoke(block.flows)
for _,block in pairs(df.global.world.map.map_blocks) do
if clearSmoke(block.flows) then
dfhack.maps.enableBlockUpdates(block, true)
end
end

for flow,_ in pairs(flows_to_delete) do
if flow then
flow:delete()
end
end
1 change: 0 additions & 1 deletion docs/clear-smoke.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ clear-smoke
:summary: Removes all smoke from the map.
:tags: fort armok fps map

Note that this can leak memory and should be used sparingly.

Usage
-----
Expand Down