summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-05-19 19:17:56 +0000
committersmatz <smatz@openttd.org>2008-05-19 19:17:56 +0000
commitf244b6b36178642ba9e429897c2f02a4d59c7f12 (patch)
tree7df9903a1f8ad20cab7cec0d49d26b6c8cfb6d61 /src
parent5cedf77a9ad8d1256dd0da3fcfe5bcae2bb79073 (diff)
downloadopenttd-f244b6b36178642ba9e429897c2f02a4d59c7f12.tar.xz
(svn r13191) -Fix: segfault after confirming query subwindow in the Generate New World window
Diffstat (limited to 'src')
-rw-r--r--src/misc_gui.cpp25
-rw-r--r--src/textbuf_gui.h4
2 files changed, 18 insertions, 11 deletions
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index 4e5ea1b14..d1baabe94 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -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);
}
diff --git a/src/textbuf_gui.h b/src/textbuf_gui.h
index 13778cea8..4e61df659 100644
--- a/src/textbuf_gui.h
+++ b/src/textbuf_gui.h
@@ -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;