Don't crash if "gps" is null

develop
Quietust 2012-05-23 13:38:01 -05:00
parent 985533460c
commit 64ea06bbfe
2 changed files with 22 additions and 7 deletions

@ -998,16 +998,29 @@ bool Gui::setDesignationCoords (const int32_t x, const int32_t y, const int32_t
bool Gui::getMousePos (int32_t & x, int32_t & y)
{
x = gps->mouse_x;
y = gps->mouse_y;
if (gps) {
x = gps->mouse_x;
y = gps->mouse_y;
}
else {
x = -1;
y = -1;
}
return (x == -1) ? false : true;
}
bool Gui::getWindowSize (int32_t &width, int32_t &height)
{
width = gps->dimx;
height = gps->dimy;
return true;
if (gps) {
width = gps->dimx;
height = gps->dimy;
return true;
}
else {
width = 80;
height = 25;
return false;
}
}
bool Gui::getMenuWidth(uint8_t &menu_width, uint8_t &area_map_width)

@ -34,10 +34,12 @@ distribution.
#include "modules/Windows.h"
using namespace DFHack;
using df::global::gps;
Windows::df_screentile *Windows::getScreenBuffer()
{
return (df_screentile *) df::global::gps->screen;
if (!gps) return NULL;
return (df_screentile *) gps->screen;
}
Windows::df_window::df_window(int x, int y, unsigned int width, unsigned int height)
@ -79,7 +81,7 @@ bool Windows::df_window::unlock (painter * painter)
return false;
}
Windows::top_level_window::top_level_window(): df_window(0,0,df::global::gps->dimx,df::global::gps->dimy)
Windows::top_level_window::top_level_window() : df_window(0,0,gps ? gps->dimx : 80,gps ? gps->dimy : 25)
{
buffer = 0;
}