diff options
author | alberth <alberth@openttd.org> | 2014-12-18 18:20:59 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2014-12-18 18:20:59 +0000 |
commit | 78896895cf23deead6ebffe6bcd615729a833d3a (patch) | |
tree | bde57b63ba75b2e7863c122a45ef968faf37232d /src | |
parent | edea2ce96d3f00ad16a6efbc9a63f7663f8ef640 (diff) | |
download | openttd-78896895cf23deead6ebffe6bcd615729a833d3a.tar.xz |
(svn r27085) -Fix: Always return a valid window to the world generation gui code.
Diffstat (limited to 'src')
-rw-r--r-- | src/genworld_gui.cpp | 3 | ||||
-rw-r--r-- | src/window_gui.h | 8 |
2 files changed, 7 insertions, 4 deletions
diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index 6ea4b5f62..603fef90d 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -837,7 +837,8 @@ static void _ShowGenerateLandscape(GenenerateLandscapeWindowMode mode) if (!GetHeightmapDimensions(_file_to_saveload.name, &x, &y)) return; } - GenerateLandscapeWindow *w = AllocateWindowDescFront<GenerateLandscapeWindow>((mode == GLWM_HEIGHTMAP) ? &_heightmap_load_desc : &_generate_landscape_desc, mode); + WindowDesc *desc = (mode == GLWM_HEIGHTMAP) ? &_heightmap_load_desc : &_generate_landscape_desc; + GenerateLandscapeWindow *w = AllocateWindowDescFront<GenerateLandscapeWindow>(desc, mode, true); if (mode == GLWM_HEIGHTMAP) { w->x = x; diff --git a/src/window_gui.h b/src/window_gui.h index 539156560..70b80c682 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -851,12 +851,14 @@ Window *FindWindowFromPt(int x, int y); * @tparam Wcls %Window class to use if the window does not exist. * @param desc The pointer to the WindowDesc to be created * @param window_number the window number of the new window - * @return %Window pointer of the newly created window, or \c NULL. + * @param return_existing If set, also return the window if it already existed. + * @return %Window pointer of the newly created window, or the existing one if \a return_existing is set, or \c NULL. */ template <typename Wcls> -Wcls *AllocateWindowDescFront(WindowDesc *desc, int window_number) +Wcls *AllocateWindowDescFront(WindowDesc *desc, int window_number, bool return_existing = false) { - if (BringWindowToFrontById(desc->cls, window_number)) return NULL; + Wcls *w = static_cast<Wcls *>(BringWindowToFrontById(desc->cls, window_number)); + if (w != NULL) return return_existing ? w : NULL; return new Wcls(desc, window_number); } |