Let CKernel clean-up. Use unused CSound::Shutdown

This commit is contained in:
Learath 2022-09-16 16:31:36 +02:00
parent fece84c892
commit f91a3069c3
8 changed files with 31 additions and 24 deletions

View file

@ -3049,19 +3049,6 @@ void CClient::Run()
g_UuidManager.DebugDump(); g_UuidManager.DebugDump();
} }
// init SDL
{
if(SDL_Init(0) < 0)
{
dbg_msg("client", "unable to init SDL base: %s", SDL_GetError());
return;
}
#ifndef CONF_PLATFORM_ANDROID
atexit(SDL_Quit);
#endif
}
// init graphics // init graphics
{ {
m_pGraphics = CreateEngineGraphicsThreaded(); m_pGraphics = CreateEngineGraphicsThreaded();
@ -3492,11 +3479,6 @@ void CClient::Run()
m_aNetClient[i].Close(); m_aNetClient[i].Close();
delete m_pEditor; delete m_pEditor;
m_pInput->Shutdown();
m_pGraphics->Shutdown();
// shutdown SDL
SDL_Quit();
} }
bool CClient::CtrlShiftKey(int Key, bool &Last) bool CClient::CtrlShiftKey(int Key, bool &Last)
@ -4788,6 +4770,17 @@ int main(int argc, const char **argv)
} }
} }
// init SDL
if(SDL_Init(0) < 0)
{
dbg_msg("client", "unable to init SDL base: %s", SDL_GetError());
return -1;
}
#ifndef CONF_PLATFORM_ANDROID
atexit(SDL_Quit);
#endif
// run the client // run the client
dbg_msg("client", "starting..."); dbg_msg("client", "starting...");
pClient->Run(); pClient->Run();
@ -4806,8 +4799,12 @@ int main(int argc, const char **argv)
shell_execute(pStorage->GetBinaryPath(PLAT_CLIENT_EXEC, aBuf, sizeof aBuf)); shell_execute(pStorage->GetBinaryPath(PLAT_CLIENT_EXEC, aBuf, sizeof aBuf));
} }
pKernel->Shutdown();
delete pKernel; delete pKernel;
// shutdown SDL
SDL_Quit();
#ifdef CONF_PLATFORM_ANDROID #ifdef CONF_PLATFORM_ANDROID
// properly close this native thread, so globals are destructed // properly close this native thread, so globals are destructed
std::exit(0); std::exit(0);

View file

@ -342,7 +342,7 @@ int CSound::Update()
return 0; return 0;
} }
int CSound::Shutdown() void CSound::Shutdown()
{ {
for(unsigned SampleID = 0; SampleID < NUM_SAMPLES; SampleID++) for(unsigned SampleID = 0; SampleID < NUM_SAMPLES; SampleID++)
{ {
@ -353,7 +353,6 @@ int CSound::Shutdown()
SDL_QuitSubSystem(SDL_INIT_AUDIO); SDL_QuitSubSystem(SDL_INIT_AUDIO);
free(m_pMixBuffer); free(m_pMixBuffer);
m_pMixBuffer = 0; m_pMixBuffer = 0;
return 0;
} }
int CSound::AllocID() int CSound::AllocID()

View file

@ -30,7 +30,7 @@ class CSound : public IEngineSound
public: public:
int Init() override; int Init() override;
int Update() override; int Update() override;
int Shutdown() override; void Shutdown() override;
bool IsSoundEnabled() override { return m_SoundEnabled; } bool IsSoundEnabled() override { return m_SoundEnabled; }

View file

@ -524,7 +524,7 @@ class IEngineGraphics : public IGraphics
MACRO_INTERFACE("enginegraphics", 0) MACRO_INTERFACE("enginegraphics", 0)
public: public:
virtual int Init() = 0; virtual int Init() = 0;
virtual void Shutdown() = 0; virtual void Shutdown() override = 0;
virtual void Minimize() = 0; virtual void Minimize() = 0;
virtual void Maximize() = 0; virtual void Maximize() = 0;

View file

@ -128,7 +128,7 @@ class IEngineInput : public IInput
MACRO_INTERFACE("engineinput", 0) MACRO_INTERFACE("engineinput", 0)
public: public:
virtual void Init() = 0; virtual void Init() = 0;
virtual void Shutdown() = 0; virtual void Shutdown() override = 0;
virtual int Update() = 0; virtual int Update() = 0;
virtual int VideoRestartNeeded() = 0; virtual int VideoRestartNeeded() = 0;
}; };

View file

@ -20,6 +20,7 @@ protected:
public: public:
IInterface() : IInterface() :
m_pKernel(nullptr) {} m_pKernel(nullptr) {}
virtual void Shutdown() {}
virtual ~IInterface() {} virtual ~IInterface() {}
}; };
@ -40,6 +41,7 @@ class IKernel
public: public:
static IKernel *Create(); static IKernel *Create();
virtual void Shutdown() = 0;
virtual ~IKernel() {} virtual ~IKernel() {}
// templated access to handle pointer conversions and interface names // templated access to handle pointer conversions and interface names

View file

@ -44,6 +44,15 @@ public:
m_NumInterfaces = 0; m_NumInterfaces = 0;
} }
void Shutdown() override
{
for(int i = m_NumInterfaces - 1; i >= 0; i--)
{
if(m_aInterfaces[i].m_AutoDestroy)
m_aInterfaces[i].m_pInterface->Shutdown();
}
}
virtual ~CKernel() virtual ~CKernel()
{ {
// delete interfaces in reverse order just the way it would happen to objects on the stack // delete interfaces in reverse order just the way it would happen to objects on the stack

View file

@ -110,7 +110,7 @@ class IEngineSound : public ISound
public: public:
virtual int Init() = 0; virtual int Init() = 0;
virtual int Update() = 0; virtual int Update() = 0;
virtual int Shutdown() = 0; virtual void Shutdown() override = 0;
}; };
extern IEngineSound *CreateEngineSound(); extern IEngineSound *CreateEngineSound();