mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 06:28:19 +00:00
Merge #2050
2050: Fix race condition. Closes #2004 r=def- a=Learath2 I guess a new state is better then a global variable Co-authored-by: Learath <learath2@gmail.com>
This commit is contained in:
commit
72fcf9caa8
|
@ -71,6 +71,7 @@ public:
|
|||
STATE_ONLINE,
|
||||
STATE_DEMOPLAYBACK,
|
||||
STATE_QUITING,
|
||||
STATE_RESTARTING,
|
||||
};
|
||||
|
||||
//
|
||||
|
|
|
@ -552,7 +552,7 @@ int *CClient::GetDirectInput(int Tick)
|
|||
// ------ state handling -----
|
||||
void CClient::SetState(int s)
|
||||
{
|
||||
if(m_State == IClient::STATE_QUITING)
|
||||
if(m_State == IClient::STATE_QUITING || m_State == IClient::STATE_RESTARTING)
|
||||
return;
|
||||
|
||||
int Old = m_State;
|
||||
|
@ -1021,9 +1021,7 @@ void CClient::DebugRender()
|
|||
|
||||
void CClient::Restart()
|
||||
{
|
||||
char aBuf[512];
|
||||
shell_execute(Storage()->GetBinaryPath(PLAT_CLIENT_EXEC, aBuf, sizeof aBuf));
|
||||
Quit();
|
||||
SetState(IClient::STATE_RESTARTING);
|
||||
}
|
||||
|
||||
void CClient::Quit()
|
||||
|
@ -2371,7 +2369,7 @@ void CClient::PumpNetwork()
|
|||
if(State() != IClient::STATE_DEMOPLAYBACK)
|
||||
{
|
||||
// check for errors
|
||||
if(State() != IClient::STATE_OFFLINE && State() != IClient::STATE_QUITING && m_NetClient[CLIENT_MAIN].State() == NETSTATE_OFFLINE)
|
||||
if(State() != IClient::STATE_OFFLINE && State() < IClient::STATE_QUITING && m_NetClient[CLIENT_MAIN].State() == NETSTATE_OFFLINE)
|
||||
{
|
||||
SetState(IClient::STATE_OFFLINE);
|
||||
Disconnect();
|
||||
|
@ -3089,7 +3087,7 @@ void CClient::Run()
|
|||
AutoCSV_Cleanup();
|
||||
|
||||
// check conditions
|
||||
if(State() == IClient::STATE_QUITING)
|
||||
if(State() == IClient::STATE_QUITING || State() == IClient::STATE_RESTARTING)
|
||||
break;
|
||||
|
||||
#if defined(CONF_FAMILY_UNIX)
|
||||
|
@ -4064,10 +4062,18 @@ int main(int argc, const char **argv) // ignore_convention
|
|||
// write down the config and quit
|
||||
pConfig->Save();
|
||||
|
||||
delete pKernel;
|
||||
bool Restarting = pClient->State() == CClient::STATE_RESTARTING;
|
||||
|
||||
pClient->~CClient();
|
||||
free(pClient);
|
||||
|
||||
if(Restarting)
|
||||
{
|
||||
char aBuf[512];
|
||||
shell_execute(pStorage->GetBinaryPath(PLAT_CLIENT_EXEC, aBuf, sizeof aBuf));
|
||||
}
|
||||
|
||||
delete pKernel;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue