FS#5567 - Crash in newobject window

Attached to Project: OpenTTD
Opened by Zooks (zooks) - Thursday, 30 May 2013, 19:38 GMT
Last edited by frosch (frosch) - Sunday, 30 June 2013, 14:40 GMT
Type Bug
Category Interface
Status Closed
Assigned To Sébastien Brissaud (sbr)
Operating System All
Severity High
Priority Normal
Reported Version trunk
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 1
Private No


Trunk r25306

Steps to reproduce:

1. open object window
2. select motorways
3. scroll down and select median with third lane
4. close object window
5. open object window again

It also occurs when selecting different objects in step 3

Grf attached
This task depends upon

Closed by  frosch (frosch)
Sunday, 30 June 2013, 14:40 GMT
Reason for closing:  Fixed
Additional comments about closing:  in r25538. Thanks to sbr for the patches :)
Comment by Sébastien Brissaud (sbr) - Friday, 31 May 2013, 21:03 GMT
When opening the BuildObjectWindow, the index of the selected object is passed to NWidgetMatrix::SetClicked().
However this method expect the UI index of the object, not its spec index.

Please find attached a patch against r25306.
Comment by frosch (frosch) - Saturday, 01 June 2013, 11:31 GMT
The BuildObjectWindow constructor looks kind of weird.
Usually SelectOtherObject does the SetClicked stuff, but currently SelectOtherObject is called very early in the constructor and only after that the matrix is initialised, which seems to be needed after changing the selected class.
In fact the matrix->SetCount is only called in the constructor and in OnClick, but not when SelectFirstAvailableObject switches the class (which is only called via the constructor).

Would this get better, if there was a SelectOtherClass method, which would do the matrix configuration, and which would be called from SelectFirstAvailableObject, OnClick etc.?
Comment by Sébastien Brissaud (sbr) - Tuesday, 04 June 2013, 21:20 GMT
The first patch is just bumped to r25321.
The second patch initialize the object matrix before trying to restore the selected object. SetClicked() in SelectOtherObject() when called from the constructor is now active. That eleminate the need of a second call to SetClicked() at the end of the constructor.
The third patch introduce a SelectOtherClass() method to remove duplication when a new object class is selected.
The fourth patch resize the window before setting up the object matrix to ensure SetClicked() works properly when a custom window size is restored.

Please find attached these fourth patches against r25321.