-
Notifications
You must be signed in to change notification settings - Fork 199
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
Conversation
Could potentially expand this script to be general-purpose |
clear-smoke.lua
Outdated
flows:erase(i) | ||
flows_to_delete[flow] = true |
There was a problem hiding this comment.
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
Given Discord discussion, the script should now be something like this: function removeFlow(flow) --have DF remove the flow
if not flow then
return
end
flow.flags.DEAD = true
local block = dfhack.maps.getTileBlock(flow.pos)
if block then
block.flow_pool.flags.active = true
else
df.global.world.orphaned_flow_pool.flags.active = true
end
end
function removeFlows(flow_type) --remove all if flow_type is nil
local count = 0
for _,flow in ipairs(df.global.flows) do
if not flow.flags.DEAD and (flow_type == nil or flow.type == flow_type) then
removeFlow(flow)
count = count + 1
end
end
return count
end
function clearSmoke()
if dfhack.isWorldLoaded() then
print(('%d smoke flows removed.'):format(removeFlows(df.flow_type.Smoke)))
else
qerror('World not loaded!')
end
end
clearSmoke() I think we could probably turn this into a |
clear-smoke.lua
Outdated
end | ||
|
||
clearSmoke() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be
if not dfhack_flags.module then
clearSmoke()
end
so it doesn't run when used as a module.
Also, there's an issue with your end of file. Post a comment on this PR that says pre-commit.ci autofix
to fix it.
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
Delete the instances of smoke that are already erased from the
flows
vectorsthanks @Bumber64 for the help!