[2.0.60] Removing a mod can invalidate buttons from other mods in mod_gui flow
Posted: Thu Aug 14, 2025 7:00 pm
If two mods add buttons to the the mod gui button flow (mod_gui.get_button_flow), then one mod is removed from a save, sometimes buttons from the remaining mod become invalid. Whether this happens appears to depend on the order the buttons were added, or possibly the mod load order.
Reproduction steps:
1) Download and enable the attached mods (simple mods to demonstrate this issue - they each create a button in the mod_gui, and reference that button in the button clicked and on_player_cursor_stack_changed events).
2) Start a new game, and make a save.
3) Disable mod "AAAA", then reload the save.
4) Notice that both buttons have been removed from the top-left mod gui flow.
5) Pick up something with your cursor to trigger the event, and observe a crash due to the button now being invalid:
There appears to be an order dependency here - if in step 3 you instead disable mod "BBBB" and reload the save, the issue does not occur. The button created by AAAA is still in the button flow, clicking it works, and the cursor change event continues to work.
Ideally, removing an unrelated mod should not invalidate buttons created by a different mod, and not be dependent on the order those buttons were created.
Reproduction steps:
1) Download and enable the attached mods (simple mods to demonstrate this issue - they each create a button in the mod_gui, and reference that button in the button clicked and on_player_cursor_stack_changed events).
2) Start a new game, and make a save.
3) Disable mod "AAAA", then reload the save.
4) Notice that both buttons have been removed from the top-left mod gui flow.
5) Pick up something with your cursor to trigger the event, and observe a crash due to the button now being invalid:
Code: Select all
Error while running event BBBB::on_player_cursor_stack_changed (ID 36)
LuaGuiElement API call when LuaGuiElement was invalid.
stack traceback:
[C]: in function '__index'
__BBBB__/control.lua:33: in function <__BBBB__/control.lua:
There appears to be an order dependency here - if in step 3 you instead disable mod "BBBB" and reload the save, the issue does not occur. The button created by AAAA is still in the button flow, clicking it works, and the cursor change event continues to work.
Ideally, removing an unrelated mod should not invalidate buttons created by a different mod, and not be dependent on the order those buttons were created.