Initialize in order to ensure destruction in order (fixes #848)

This commit is contained in:
def 2017-08-30 17:22:36 +02:00
parent 25a5eff1f8
commit 7f0eb53ff4

View file

@ -2636,7 +2636,7 @@ void CClient::InitInterfaces()
// fetch interfaces
m_pEngine = Kernel()->RequestInterface<IEngine>();
m_pEditor = Kernel()->RequestInterface<IEditor>();
//m_pGraphics = Kernel()->RequestInterface<IEngineGraphics>();
m_pGraphics = Kernel()->RequestInterface<IEngineGraphics>();
m_pSound = Kernel()->RequestInterface<IEngineSound>();
m_pGameClient = Kernel()->RequestInterface<IGameClient>();
m_pInput = Kernel()->RequestInterface<IEngineInput>();
@ -2699,21 +2699,6 @@ void CClient::Run()
atexit(SDL_Quit); // ignore_convention
}
// init graphics
{
m_pGraphics = CreateEngineGraphicsThreaded();
bool RegisterFail = false;
RegisterFail = RegisterFail || !Kernel()->RegisterInterface(static_cast<IEngineGraphics*>(m_pGraphics)); // register graphics as both
RegisterFail = RegisterFail || !Kernel()->RegisterInterface(static_cast<IGraphics*>(m_pGraphics), false);
if(RegisterFail || m_pGraphics->Init() != 0)
{
dbg_msg("client", "couldn't init graphics");
return;
}
}
// init sound, allowed to fail
m_SoundInitFailed = Sound()->Init() != 0;
@ -3557,6 +3542,7 @@ int main(int argc, const char **argv) // ignore_convention
IConsole *pConsole = CreateConsole(CFGFLAG_CLIENT);
IStorage *pStorage = CreateStorage("Teeworlds", IStorage::STORAGETYPE_CLIENT, argc, argv); // ignore_convention
IConfig *pConfig = CreateConfig();
IEngineGraphics *pGraphics = CreateEngineGraphicsThreaded();
IEngineSound *pEngineSound = CreateEngineSound();
IEngineInput *pEngineInput = CreateEngineInput();
IEngineTextRender *pEngineTextRender = CreateEngineTextRender();
@ -3585,6 +3571,9 @@ int main(int argc, const char **argv) // ignore_convention
RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast<IEngineMasterServer*>(pEngineMasterServer)); // register as both
RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast<IMasterServer*>(pEngineMasterServer), false);
RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast<IEngineGraphics*>(pGraphics)); // register as both
RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast<IGraphics*>(pGraphics), false);
RegisterFail = RegisterFail || !pKernel->RegisterInterface(CreateEditor());
RegisterFail = RegisterFail || !pKernel->RegisterInterface(CreateGameClient(), false);
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pStorage);
@ -3603,6 +3592,15 @@ int main(int argc, const char **argv) // ignore_convention
pEngineMasterServer->Init();
pEngineMasterServer->Load();
// init graphics
{
if(pGraphics->Init() != 0)
{
dbg_msg("client", "couldn't init graphics");
return -1;
}
}
// register all console commands
pClient->RegisterCommands();