The International Simutrans Forum

Development => Patches & Projects => Topic started by: janry on May 20, 2026, 08:24:23 PM

Title: simworld: wrap karte_t::step body with intr_disable/intr_enable
Post by: janry on May 20, 2026, 08:24:23 PM
INT_CHECK calls inside karte_t::step (during fab_list iteration in
simfab.cc, and several explicit INT_CHECK("...") sites in simworld.cc
itself) can pump GUI events while step is mid-iteration over
fab_list / convoi_array / cities. If a welt_gui_t ("New world")
dialog is open, its "Start" handler in gui/welt.cc calls
welt->init(), which runs karte_t::destroy() and frees the very
factory whose step is on the stack. ASAN reports a
heap-use-after-free in array_tpl<ware_production_t>::get_count.

The karte_t::interactive() loop calls step() with no wrap; only
modal_dialogue() in gui/simwin.cc currently guards the call with
intr_disable()/intr_enable(). Pushing the wrap into step() itself
makes the guard apply to every caller and renders the
modal_dialogue wrap redundant (harmless, can be removed in a
follow-up if desired).
Title: Re: simworld: wrap karte_t::step body with intr_disable/intr_enable
Post by: prissi on May 21, 2026, 06:36:42 AM
Depending on map size, mouse movements without enough INT_CHECK can be very sloppy. The proper way is to do this interaction by a tool. Same needs to be done for loading/scenarios/ ....

I tried this with a very large map and it was dramatic, fps dripping to 2 while before still 7-10 were possible.

For the moment, I changed the list to numerical enumerators as ancient C which will somewhat cope with deleting factories etc. while iterating.
Title: Re: simworld: wrap karte_t::step body with intr_disable/intr_enable
Post by: janry on May 21, 2026, 02:49:12 PM
something like this?