mirror of
https://github.com/ddnet/ddnet.git
synced 2024-09-20 01:24:18 +00:00
Merge #5840
5840: Let CKernel clean-up. Use unused CSound::Shutdown r=heinrich5991 a=Learath2 <!-- What is the motivation for the changes of this pull request? --> Minor cleanup in preparation for the replacement I'll push for #5092. <!-- Note that builds and other checks will be run for your change. Don't feel intimidated by failures in some of the checks. If you can't resolve them yourself, experienced devs can also resolve them before merging your pull request. --> ## Checklist - [x] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test (especially base/) or added coverage to integration test - [x] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: Learath <learath2@gmail.com>
This commit is contained in:
commit
aace02991a
|
@ -3049,19 +3049,6 @@ void CClient::Run()
|
|||
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
|
||||
{
|
||||
m_pGraphics = CreateEngineGraphicsThreaded();
|
||||
|
@ -3492,11 +3479,6 @@ void CClient::Run()
|
|||
m_aNetClient[i].Close();
|
||||
|
||||
delete m_pEditor;
|
||||
m_pInput->Shutdown();
|
||||
m_pGraphics->Shutdown();
|
||||
|
||||
// shutdown SDL
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
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
|
||||
dbg_msg("client", "starting...");
|
||||
pClient->Run();
|
||||
|
@ -4806,8 +4799,12 @@ int main(int argc, const char **argv)
|
|||
shell_execute(pStorage->GetBinaryPath(PLAT_CLIENT_EXEC, aBuf, sizeof aBuf));
|
||||
}
|
||||
|
||||
pKernel->Shutdown();
|
||||
delete pKernel;
|
||||
|
||||
// shutdown SDL
|
||||
SDL_Quit();
|
||||
|
||||
#ifdef CONF_PLATFORM_ANDROID
|
||||
// properly close this native thread, so globals are destructed
|
||||
std::exit(0);
|
||||
|
|
|
@ -342,7 +342,7 @@ int CSound::Update()
|
|||
return 0;
|
||||
}
|
||||
|
||||
int CSound::Shutdown()
|
||||
void CSound::Shutdown()
|
||||
{
|
||||
for(unsigned SampleID = 0; SampleID < NUM_SAMPLES; SampleID++)
|
||||
{
|
||||
|
@ -353,7 +353,6 @@ int CSound::Shutdown()
|
|||
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||
free(m_pMixBuffer);
|
||||
m_pMixBuffer = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CSound::AllocID()
|
||||
|
|
|
@ -30,7 +30,7 @@ class CSound : public IEngineSound
|
|||
public:
|
||||
int Init() override;
|
||||
int Update() override;
|
||||
int Shutdown() override;
|
||||
void Shutdown() override;
|
||||
|
||||
bool IsSoundEnabled() override { return m_SoundEnabled; }
|
||||
|
||||
|
|
|
@ -524,7 +524,7 @@ class IEngineGraphics : public IGraphics
|
|||
MACRO_INTERFACE("enginegraphics", 0)
|
||||
public:
|
||||
virtual int Init() = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
virtual void Shutdown() override = 0;
|
||||
|
||||
virtual void Minimize() = 0;
|
||||
virtual void Maximize() = 0;
|
||||
|
|
|
@ -128,7 +128,7 @@ class IEngineInput : public IInput
|
|||
MACRO_INTERFACE("engineinput", 0)
|
||||
public:
|
||||
virtual void Init() = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
virtual void Shutdown() override = 0;
|
||||
virtual int Update() = 0;
|
||||
virtual int VideoRestartNeeded() = 0;
|
||||
};
|
||||
|
|
|
@ -20,6 +20,7 @@ protected:
|
|||
public:
|
||||
IInterface() :
|
||||
m_pKernel(nullptr) {}
|
||||
virtual void Shutdown() {}
|
||||
virtual ~IInterface() {}
|
||||
};
|
||||
|
||||
|
@ -40,6 +41,7 @@ class IKernel
|
|||
|
||||
public:
|
||||
static IKernel *Create();
|
||||
virtual void Shutdown() = 0;
|
||||
virtual ~IKernel() {}
|
||||
|
||||
// templated access to handle pointer conversions and interface names
|
||||
|
|
|
@ -44,6 +44,15 @@ public:
|
|||
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()
|
||||
{
|
||||
// delete interfaces in reverse order just the way it would happen to objects on the stack
|
||||
|
|
|
@ -110,7 +110,7 @@ class IEngineSound : public ISound
|
|||
public:
|
||||
virtual int Init() = 0;
|
||||
virtual int Update() = 0;
|
||||
virtual int Shutdown() = 0;
|
||||
virtual void Shutdown() override = 0;
|
||||
};
|
||||
|
||||
extern IEngineSound *CreateEngineSound();
|
||||
|
|
Loading…
Reference in a new issue