Avoid crash if pressing close window button when networking

This commit is contained in:
Benau
2018-04-01 15:08:30 +08:00
parent eca5a78075
commit 66c05bbdbf
2 changed files with 12 additions and 5 deletions

View File

@@ -1942,7 +1942,11 @@ int main(int argc, char *argv[] )
// If the window was closed in the middle of a race, remove players,
// so we don't crash later when StateManager tries to access input devices.
StateManager::get()->resetActivePlayers();
if(input_manager) delete input_manager; // if early crash avoid delete NULL
if (input_manager)
{
delete input_manager;
input_manager = NULL;
}
if (STKHost::existHost())
STKHost::get()->shutdown();

View File

@@ -81,10 +81,13 @@ ClientLobby::~ClientLobby()
void ClientLobby::clearPlayers()
{
StateManager::get()->resetActivePlayers();
input_manager->getDeviceManager()->setAssignMode(NO_ASSIGN);
input_manager->getDeviceManager()->setSinglePlayer(NULL);
input_manager->setMasterPlayerOnly(false);
input_manager->getDeviceManager()->clearLatestUsedDevice();
if (input_manager)
{
input_manager->getDeviceManager()->setAssignMode(NO_ASSIGN);
input_manager->getDeviceManager()->setSinglePlayer(NULL);
input_manager->setMasterPlayerOnly(false);
input_manager->getDeviceManager()->clearLatestUsedDevice();
}
} // clearPlayers
//-----------------------------------------------------------------------------