Qt: Fix race condition when detaching a multiplayer game while running

This commit is contained in:
Jeffrey Pfau 2016-09-04 09:31:14 -07:00
parent 51e214ce5a
commit ee3edbbd19
1 changed files with 8 additions and 0 deletions

View File

@ -159,6 +159,9 @@ void MultiplayerController::detachGame(GameController* controller) {
if (!thread) { if (!thread) {
return; return;
} }
for (int i = 0; i < m_players.count(); ++i) {
m_players[i].controller->threadInterrupt();
}
#ifdef M_CORE_GBA #ifdef M_CORE_GBA
if (controller->platform() == PLATFORM_GBA) { if (controller->platform() == PLATFORM_GBA) {
GBA* gba = static_cast<GBA*>(thread->core->board); GBA* gba = static_cast<GBA*>(thread->core->board);
@ -171,12 +174,17 @@ void MultiplayerController::detachGame(GameController* controller) {
} }
} }
#endif #endif
controller->threadContinue();
for (int i = 0; i < m_players.count(); ++i) { for (int i = 0; i < m_players.count(); ++i) {
if (m_players[i].controller == controller) { if (m_players[i].controller == controller) {
m_players.removeAt(i); m_players.removeAt(i);
break; break;
} }
} }
for (int i = 0; i < m_players.count(); ++i) {
m_players[i].controller->threadContinue();
}
emit gameDetached(); emit gameDetached();
} }