Closed lethosor closed 3 years ago
Oh, statics, you bite me dearly. No wonder they name you "antipattern".
What I suspect is happening here is that the ItemFilter vector is cleared and repopulated when the state is reset on map load, but the iterator in the static still points to the cleared vector data. And since you selected the same building type as the cached iterator, it did not get reset before it was used. Excellent excellent catch. Thank you!
yup, reproduced the issue and verified the fix. thank you again for finding this.
To reproduce:
b
-b
-P
:lua df.global.save_on_exit = false
)b
-b
should result in a crashI enabled debug symbols for buildingplan(-lib) with
and got the following backtrace:
What I've found so far:
materials
is corrupted here (.size()
gives an extremely large value): https://github.com/DFHack/dfhack/blob/923b1b14f33bf6c013c1bcc49270139242ec960b/plugins/buildingplan-planner.cpp#L173filter
is assigned here, using an iterator: https://github.com/DFHack/dfhack/blob/923b1b14f33bf6c013c1bcc49270139242ec960b/plugins/buildingplan.cpp#L580 I suspect that this iterator may be invalidated when the loaded world changes, but I haven't figured out where that happens yet. Given the check at https://github.com/DFHack/dfhack/blob/923b1b14f33bf6c013c1bcc49270139242ec960b/plugins/buildingplan.cpp#L574, I suspect that this crash may not occur if using different building types in steps (2) and (5) above.I'll try to continue investigating tomorrow, but @myk002, if you're able to take a look, that would certainly be appreciated. Unsure if this occurs in r3 or just on develop.