(svn r13191) -Fix: segfault after confirming query subwindow in the Generate New World window

This commit is contained in:
smatz 2008-05-19 19:17:56 +00:00
parent 5cedf77a9a
commit f244b6b361
2 changed files with 18 additions and 11 deletions

View File

@ -1121,11 +1121,11 @@ enum QueryWidgets {
* Window used for asking the user a YES/NO question.
*/
struct QueryWindow : public Window {
void (*proc)(Window*, bool); ///< callback function executed on closing of popup. Window* points to parent, bool is true if 'yes' clicked, false otherwise
uint64 params[10]; ///< local copy of _decode_parameters
StringID message; ///< message shown for query window
QueryCallbackProc *proc; ///< callback function executed on closing of popup. Window* points to parent, bool is true if 'yes' clicked, false otherwise
uint64 params[10]; ///< local copy of _decode_parameters
StringID message; ///< message shown for query window
QueryWindow(const WindowDesc *desc, StringID caption, StringID message, Window *parent, void (*callback)(Window*, bool)) : Window(desc)
QueryWindow(const WindowDesc *desc, StringID caption, StringID message, Window *parent, QueryCallbackProc *callback) : Window(desc)
{
if (parent == NULL) parent = FindWindowById(WC_MAIN_WINDOW, 0);
this->parent = parent;
@ -1159,12 +1159,17 @@ struct QueryWindow : public Window {
virtual void OnClick(Point pt, int widget)
{
switch (widget) {
case QUERY_WIDGET_YES:
if (this->proc != NULL) {
this->proc(this->parent, true);
this->proc = NULL;
case QUERY_WIDGET_YES: {
/* in the Generate New World window, clicking 'Yes' causes
* DeleteNonVitalWindows() to be called - we shouldn't be in a window then */
QueryCallbackProc *proc = this->proc;
Window *parent = this->parent;
delete this;
if (proc != NULL) {
proc(parent, true);
proc = NULL;
}
/* Fallthrough */
} break;
case QUERY_WIDGET_NO:
delete this;
break;
@ -1215,7 +1220,7 @@ static const WindowDesc _query_desc = {
* @param parent pointer to parent window, if this pointer is NULL the parent becomes
* the main window WC_MAIN_WINDOW
* @param callback callback function pointer to set in the window descriptor*/
void ShowQuery(StringID caption, StringID message, Window *parent, void (*callback)(Window*, bool))
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
{
new QueryWindow(&_query_desc, caption, message, parent, callback);
}

View File

@ -28,8 +28,10 @@ bool MoveTextBufferPos(Textbuf *tb, int navmode);
void InitializeTextBuffer(Textbuf *tb, const char *buf, uint16 maxlength, uint16 maxwidth);
void UpdateTextBufferSize(Textbuf *tb);
typedef void QueryCallbackProc(Window*, bool);
void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth, Window *parent, CharSetFilter afilter);
void ShowQuery(StringID caption, StringID message, Window *w, void (*callback)(Window*, bool));
void ShowQuery(StringID caption, StringID message, Window *w, QueryCallbackProc *callback);
/** The number of 'characters' on the on-screen keyboard. */
static const uint OSK_KEYBOARD_ENTRIES = 50;