The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: Dwachs on September 13, 2009, 01:55:08 pm

Title: [bug+patch] crash when loading with open schedule window
Post by: Dwachs on September 13, 2009, 01:55:08 pm
Simutrans crashes if a schedule window is open and a new game is loaded. Here is a patch. I do not know however if this patch causes difficulties at other places. The window-close function mainly called in destructors, so it should not break other things.
Title: Re: [bug+patch] crash when loading with open schedule window
Post by: prissi on September 13, 2009, 08:23:57 pm
Since some of the windows are calling handles, which are not freed during destruction, it may result in crashes. Especially in MSVC, which is less forgiving for acessing objects during their destruction. Windows are only in the kill list, if they are in event handling. That means they are ****uming that there is still a valid "this" with all virtual functions, when event handling resumes. Closing the windows anyway seems like invitation of errors. Rather one needs to find out, why they are not closed by close all windows ...
Title: Re: [bug+patch] crash when loading with open schedule window
Post by: Dwachs on September 14, 2009, 05:12:40 am
The crash happens also on Linux.

Rather one needs to find out, why they are not closed by close all windows ...
Because 'inside-event-handling' is active: 'loading' is treated by the internal event handler.

How to reproduce:
Open schedule window of a convoi, load a game. What happens then:
-- All windows are moved to the kill list
-- Current world is destroyed including the convoi with open schedule window
-- Upon calling ~convoi_t it is tried to destroy the schedule window too, but since this window is in the kill list already, it is not found and hence not closed.
-- Then the kill list is processed. The schedule window is closed, but on closing it wants to cleanup schedule. However, the pointer now points to already freed memory - crash.
Title: Re: [bug+patch] crash when loading with open schedule window
Post by: prissi on September 14, 2009, 08:49:21 am
Then there might be more positions, where that fails, i.e. the clearing of the world must be moved outside from the event handler. Since the loading routine is directlz called from load frame, it should be deferred to the simmain (which would be the appropriate place anyway.)
Title: Re: [bug+patch] crash when loading with open schedule window
Post by: prissi on October 13, 2009, 07:55:45 pm
New window handling implemented, a little less braindead than the old, but still with vast room for improvement.