Skip to content

Commit

Permalink
xrCore: g_pauseMngr variable refactored to function.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Kaffeine committed Nov 25, 2015
1 parent 1f9c0ff commit cb308c1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
11 changes: 10 additions & 1 deletion src/xrCore/FTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,17 @@ void CStatTimer::FrameEnd()
else result = 0.99f*result + 0.01f*_time;
}

XRCORE_API pauseMngr g_pauseMngr;
XRCORE_API pauseMngr *g_pauseMngr()
{
static pauseMngr *manager = nullptr;

if (!manager)
{
manager = new pauseMngr();
}

return manager;
}

pauseMngr::pauseMngr() :m_paused(FALSE)
{
Expand Down
6 changes: 3 additions & 3 deletions src/xrCore/FTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class XRCORE_API pauseMngr
void UnRegister(CTimer_paused* t);
};

extern XRCORE_API pauseMngr g_pauseMngr;
extern XRCORE_API pauseMngr *g_pauseMngr();

class XRCORE_API CTimerBase
{
Expand Down Expand Up @@ -161,8 +161,8 @@ class XRCORE_API CTimer_paused_ex : public CTimer
class XRCORE_API CTimer_paused : public CTimer_paused_ex
{
public:
CTimer_paused() { g_pauseMngr.Register(this); }
virtual ~CTimer_paused() { g_pauseMngr.UnRegister(this); }
CTimer_paused() { g_pauseMngr()->Register(this); }
virtual ~CTimer_paused() { g_pauseMngr()->UnRegister(this); }
};

extern XRCORE_API BOOL g_bEnableStatGather;
Expand Down
8 changes: 4 additions & 4 deletions src/xrEngine/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ void CRenderDevice::Pause(BOOL bOn, BOOL bTimer, BOOL bSound, LPCSTR reason)
TRUE;
if (bTimer && (!g_pGamePersistent || g_pGamePersistent->CanBePaused()))
{
g_pauseMngr.Pause(TRUE);
g_pauseMngr()->Pause(TRUE);
#ifdef DEBUG
if (!xr_strcmp(reason, "li_pause_key_no_clip"))
TimerGlobal.Pause(FALSE);
Expand All @@ -413,10 +413,10 @@ void CRenderDevice::Pause(BOOL bOn, BOOL bTimer, BOOL bSound, LPCSTR reason)
}
else
{
if (bTimer && g_pauseMngr.Paused())
if (bTimer && g_pauseMngr()->Paused())
{
fTimeDelta = EPS_S + EPS_S;
g_pauseMngr.Pause(FALSE);
g_pauseMngr()->Pause(FALSE);
}
if (bSound)
{
Expand All @@ -435,7 +435,7 @@ void CRenderDevice::Pause(BOOL bOn, BOOL bTimer, BOOL bSound, LPCSTR reason)

BOOL CRenderDevice::Paused()
{
return g_pauseMngr.Paused();
return g_pauseMngr()->Paused();
}

void CRenderDevice::OnWM_Activate(WPARAM wParam, LPARAM lParam)
Expand Down

0 comments on commit cb308c1

Please sign in to comment.