From 2160338662b45c1add91a2c0dd8f03fef347dff0 Mon Sep 17 00:00:00 2001 From: rubidium Date: Thu, 13 Dec 2007 18:46:04 +0000 Subject: (svn r11629) -Fix [FS#1527]: many viewports could crash the scenario editor. --- src/viewport.cpp | 18 ++++++++++++++++-- src/window.cpp | 2 +- src/window.h | 5 +++++ 3 files changed, 22 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/viewport.cpp b/src/viewport.cpp index 96dbe753c..b9636ca11 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -32,8 +32,22 @@ ZoomLevel _saved_scrollpos_zoom; -/* XXX - maximum viewports is maximum windows - 2 (main toolbar + status bar) */ -static ViewPort _viewports[25 - 2]; +/** + * The maximum number of viewports depends on the maximum number + * of windows. Technically is could be the maximum number of + * windows, but there is always at least one window that does + * not need a viewport. Not having 'support' for that viewport + * saves some time and memory. + * For the introduction GUI and create game GUIs there is no + * need for more than one viewport, however in the normal game + * and scenario editor one can make a lot of viewports. For the + * normal game one always has a main toolbar and a status bar, + * however the statusbar does not exist on the scenario editor. + * + * This means that we can only safely assume that there is one + * window without viewport. + */ +static ViewPort _viewports[MAX_NUMBER_OF_WINDOWS - 1]; static uint32 _active_viewports; ///< bitmasked variable where each bit signifies if a viewport is in use or not assert_compile(lengthof(_viewports) < sizeof(_active_viewports) * 8); diff --git a/src/window.cpp b/src/window.cpp index 958eb4475..f5b9ac041 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -22,7 +22,7 @@ /* delta between mouse cursor and upper left corner of dragged window */ static Point _drag_delta; -static Window _windows[25]; +static Window _windows[MAX_NUMBER_OF_WINDOWS]; Window *_z_windows[lengthof(_windows)]; Window **_last_z_window; ///< always points to the next free space in the z-array diff --git a/src/window.h b/src/window.h index 1fae1a5ca..11086e64b 100644 --- a/src/window.h +++ b/src/window.h @@ -14,6 +14,11 @@ #include "vehicle.h" #include "viewport.h" +/** + * The maximum number of windows that can be opened. + */ +static const int MAX_NUMBER_OF_WINDOWS = 25; + struct WindowEvent; typedef void WindowProc(Window *w, WindowEvent *e); -- cgit v1.2.3-54-g00ecf