GUI: Do not allocate the Screen dynamically, it's always used (#442)

At least according to Isilkors analysis, this should fix the crash.
Günther Brammer 2010-10-30 01:19:54 +02:00
parent 1077728a39
commit b0d9d73af6
3 changed files with 27 additions and 18 deletions

View File

@ -327,12 +327,7 @@ bool C4Game::PreInit()
{ LogFatal(LoadResStr("IDS_ERR_NOGFXSYS")); return false; }
// load GUI
if (!pGUI)
{
int32_t iGuiResX = Config.Graphics.ResX;
int32_t iGuiResY = Config.Graphics.ResY;
pGUI = new C4GUIScreen(0, 0, iGuiResX, iGuiResY);
}
pGUI->Init(0, 0, Config.Graphics.ResX, Config.Graphics.ResY);
fPreinited = true;
@ -561,8 +556,8 @@ void C4Game::Clear()
C4AulProfiler::Abort();
// exit gui
if (pGUI) { delete pGUI; pGUI=NULL; }
pGUI->Clear();
// next mission (shoud have been transferred to C4Application now if next mission was desired)
NextMission.Clear(); NextMissionText.Clear(); NextMissionDesc.Clear();
@ -1584,7 +1579,6 @@ void C4Game::Default()
TransferZones.Default();
GroupSet.Default();
pParentGroup=NULL;
pGUI=NULL;
pScenarioSections=pCurrentScenarioSection=NULL;
*CurrentScenarioSection=0;
pGlobalEffects=NULL;

View File

@ -530,10 +530,18 @@ namespace C4GUI
}
}
Screen::Screen(int32_t tx, int32_t ty, int32_t twdt, int32_t thgt) : Window(), Mouse(tx+twdt/2, ty+thgt/2), pContext(NULL), fExclusive(true), pGamePadOpener(NULL), fZoom(1.0f)
Screen::Screen() : Window(), Mouse(0, 0), pContext(NULL), fExclusive(true), pGamePadOpener(NULL), fZoom(1.0f)
{
// no dialog active
pActiveDlg = NULL;
// set static var
pScreen = this;
}
void Screen::Init(int32_t tx, int32_t ty, int32_t twdt, int32_t thgt)
{
Mouse.x = tx+twdt/2;
Mouse.y = ty+thgt/2;
// calculate zoom
float fZoomX = float(Config.Graphics.ResX) / twdt;
float fZoomY = float(Config.Graphics.ResY) / thgt;
@ -541,23 +549,25 @@ namespace C4GUI
// set size - calcs client area as well
SetBounds(C4Rect(tx,ty,twdt,thgt));
SetPreferredDlgRect(C4Rect(0,0,twdt,thgt));
// set static var
pScreen = this;
// GamePad
if (Application.pGamePadControl && Config.Controls.GamepadGuiControl)
pGamePadOpener = new C4GamePadOpener(0);
}
Screen::~Screen()
void Screen::Clear()
{
// dtor: Close context menu
AbortContext(false);
// clear singleton
if (this == pScreen) pScreen = NULL;
// GamePad
if (pGamePadOpener) delete pGamePadOpener;
}
Screen::~Screen()
{
// clear singleton
if (this == pScreen) pScreen = NULL;
}
void Screen::ElementPosChanged(Element *pOfElement)
{
// redraw fullscreen BG if dlgs are dragged around in shared mode
@ -1050,6 +1060,7 @@ namespace C4GUI
}
}
Screen TheScreen;
// --------------------------------------------------
// ComponentAligner
@ -1186,4 +1197,4 @@ namespace C4GUI
} // end of namespace
C4GUIScreen *pGUI;
C4GUIScreen *pGUI = &C4GUI::TheScreen;

View File

@ -2512,8 +2512,11 @@ namespace C4GUI
Dialog *GetTopDialog(); // get topmost dlg
public:
Screen(int32_t tx, int32_t ty, int32_t twdt, int32_t thgt); // ctor
~Screen(); // dtor
Screen();
~Screen();
void Init(int32_t tx, int32_t ty, int32_t twdt, int32_t thgt);
void Clear();
void Render(bool fDoBG); // render to lpDDraw
void RenderMouse(C4TargetFacet &cgo); // draw mouse only
@ -2727,6 +2730,7 @@ namespace C4GUI
inline void MouseMove(int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyParam, class C4Viewport *pVP) // pVP specified for console mode viewports only
{ Screen *s=Screen::GetScreenS(); if(s) s->MouseMove(iButton, iX, iY, dwKeyParam, pVP); }
extern Screen TheScreen;
} // end of namespace
typedef C4GUI::Screen C4GUIScreen;