Skip to content

Commit cb308c1

Browse files
committed
xrCore: g_pauseMngr variable refactored to function.
g_pauseMngr constructor calls reserve() on m_timers member, which requires dynamic memory allocation, which triggers xrMemory initialization. The point is that xrMemory relies on command line arguments, which we *can not* extract from main argc/argv pair, because g_pauseMngr constructor executed before main(). With g_pauseMngr being a function, we delay the manager construction to the first function call, which fixes the issue.
1 parent 1f9c0ff commit cb308c1

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/xrCore/FTimer.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,17 @@ void CStatTimer::FrameEnd()
2222
else result = 0.99f*result + 0.01f*_time;
2323
}
2424

25-
XRCORE_API pauseMngr g_pauseMngr;
25+
XRCORE_API pauseMngr *g_pauseMngr()
26+
{
27+
static pauseMngr *manager = nullptr;
28+
29+
if (!manager)
30+
{
31+
manager = new pauseMngr();
32+
}
2633

34+
return manager;
35+
}
2736

2837
pauseMngr::pauseMngr() :m_paused(FALSE)
2938
{

src/xrCore/FTimer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class XRCORE_API pauseMngr
1616
void UnRegister(CTimer_paused* t);
1717
};
1818

19-
extern XRCORE_API pauseMngr g_pauseMngr;
19+
extern XRCORE_API pauseMngr *g_pauseMngr();
2020

2121
class XRCORE_API CTimerBase
2222
{
@@ -161,8 +161,8 @@ class XRCORE_API CTimer_paused_ex : public CTimer
161161
class XRCORE_API CTimer_paused : public CTimer_paused_ex
162162
{
163163
public:
164-
CTimer_paused() { g_pauseMngr.Register(this); }
165-
virtual ~CTimer_paused() { g_pauseMngr.UnRegister(this); }
164+
CTimer_paused() { g_pauseMngr()->Register(this); }
165+
virtual ~CTimer_paused() { g_pauseMngr()->UnRegister(this); }
166166
};
167167

168168
extern XRCORE_API BOOL g_bEnableStatGather;

src/xrEngine/device.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ void CRenderDevice::Pause(BOOL bOn, BOOL bTimer, BOOL bSound, LPCSTR reason)
402402
TRUE;
403403
if (bTimer && (!g_pGamePersistent || g_pGamePersistent->CanBePaused()))
404404
{
405-
g_pauseMngr.Pause(TRUE);
405+
g_pauseMngr()->Pause(TRUE);
406406
#ifdef DEBUG
407407
if (!xr_strcmp(reason, "li_pause_key_no_clip"))
408408
TimerGlobal.Pause(FALSE);
@@ -413,10 +413,10 @@ void CRenderDevice::Pause(BOOL bOn, BOOL bTimer, BOOL bSound, LPCSTR reason)
413413
}
414414
else
415415
{
416-
if (bTimer && g_pauseMngr.Paused())
416+
if (bTimer && g_pauseMngr()->Paused())
417417
{
418418
fTimeDelta = EPS_S + EPS_S;
419-
g_pauseMngr.Pause(FALSE);
419+
g_pauseMngr()->Pause(FALSE);
420420
}
421421
if (bSound)
422422
{
@@ -435,7 +435,7 @@ void CRenderDevice::Pause(BOOL bOn, BOOL bTimer, BOOL bSound, LPCSTR reason)
435435

436436
BOOL CRenderDevice::Paused()
437437
{
438-
return g_pauseMngr.Paused();
438+
return g_pauseMngr()->Paused();
439439
}
440440

441441
void CRenderDevice::OnWM_Activate(WPARAM wParam, LPARAM lParam)

0 commit comments

Comments
 (0)