Commit 2e79f68d authored by Fluorohydride's avatar Fluorohydride

Merge pull request #516 from soarqin/official

Resolved the crash problem under posix due to run glGenTextures and glDeleteTextures in different threads
parents cdcd1e37 e9dfbcc9
...@@ -159,7 +159,9 @@ void DuelClient::ClientEvent(bufferevent *bev, short events, void *ctx) { ...@@ -159,7 +159,9 @@ void DuelClient::ClientEvent(bufferevent *bev, short events, void *ctx) {
mainGame->btnCreateHost->setEnabled(true); mainGame->btnCreateHost->setEnabled(true);
mainGame->btnJoinHost->setEnabled(true); mainGame->btnJoinHost->setEnabled(true);
mainGame->btnJoinCancel->setEnabled(true); mainGame->btnJoinCancel->setEnabled(true);
mainGame->CloseDuelWindow(); mainGame->closeDoneSignal.Reset();
mainGame->closeSignal.Set();
mainGame->closeDoneSignal.Wait();
mainGame->dInfo.isStarted = false; mainGame->dInfo.isStarted = false;
mainGame->is_building = false; mainGame->is_building = false;
mainGame->device->setEventReceiver(&mainGame->menuHandler); mainGame->device->setEventReceiver(&mainGame->menuHandler);
...@@ -498,7 +500,9 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) { ...@@ -498,7 +500,9 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
mainGame->actionSignal.Reset(); mainGame->actionSignal.Reset();
mainGame->actionSignal.Wait(); mainGame->actionSignal.Wait();
mainGame->gMutex.Lock(); mainGame->gMutex.Lock();
mainGame->CloseDuelWindow(); mainGame->closeDoneSignal.Reset();
mainGame->closeSignal.Set();
mainGame->closeDoneSignal.Wait();
mainGame->dInfo.isStarted = false; mainGame->dInfo.isStarted = false;
mainGame->btnCreateHost->setEnabled(true); mainGame->btnCreateHost->setEnabled(true);
mainGame->btnJoinHost->setEnabled(true); mainGame->btnJoinHost->setEnabled(true);
...@@ -701,7 +705,9 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -701,7 +705,9 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
mainGame->actionSignal.Reset(); mainGame->actionSignal.Reset();
mainGame->actionSignal.Wait(); mainGame->actionSignal.Wait();
mainGame->gMutex.Lock(); mainGame->gMutex.Lock();
mainGame->CloseDuelWindow(); mainGame->closeDoneSignal.Reset();
mainGame->closeSignal.Set();
mainGame->closeDoneSignal.Wait();
mainGame->dInfo.isStarted = false; mainGame->dInfo.isStarted = false;
mainGame->btnCreateHost->setEnabled(true); mainGame->btnCreateHost->setEnabled(true);
mainGame->btnJoinHost->setEnabled(true); mainGame->btnJoinHost->setEnabled(true);
......
...@@ -100,7 +100,6 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -100,7 +100,6 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
} }
if(mainGame->dInfo.player_type == 7) { if(mainGame->dInfo.player_type == 7) {
DuelClient::StopClient(); DuelClient::StopClient();
mainGame->CloseDuelWindow();
mainGame->dInfo.isStarted = false; mainGame->dInfo.isStarted = false;
mainGame->device->setEventReceiver(&mainGame->menuHandler); mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->btnCreateHost->setEnabled(true); mainGame->btnCreateHost->setEnabled(true);
......
...@@ -541,6 +541,8 @@ void Game::MainLoop() { ...@@ -541,6 +541,8 @@ void Game::MainLoop() {
} }
} }
driver->endScene(); driver->endScene();
if(closeSignal.Wait(0))
CloseDuelWindow();
fps++; fps++;
cur_time = timer->getTime(); cur_time = timer->getTime();
if(cur_time < fps * 17 - 20) if(cur_time < fps * 17 - 20)
...@@ -905,6 +907,7 @@ void Game::CloseDuelWindow() { ...@@ -905,6 +907,7 @@ void Game::CloseDuelWindow() {
lstHostList->clear(); lstHostList->clear();
DuelClient::hosts.clear(); DuelClient::hosts.clear();
ClearTextures(); ClearTextures();
closeDoneSignal.Set();
} }
int Game::LocalPlayer(int player) { int Game::LocalPlayer(int player) {
return dInfo.isFirst ? player : 1 - player; return dInfo.isFirst ? player : 1 - player;
......
...@@ -102,6 +102,8 @@ public: ...@@ -102,6 +102,8 @@ public:
Signal actionSignal; Signal actionSignal;
Signal replaySignal; Signal replaySignal;
Signal singleSignal; Signal singleSignal;
Signal closeSignal;
Signal closeDoneSignal;
Config gameConf; Config gameConf;
DuelInfo dInfo; DuelInfo dInfo;
......
...@@ -25,6 +25,11 @@ public: ...@@ -25,6 +25,11 @@ public:
return; return;
WaitForSingleObject(_event, INFINITE); WaitForSingleObject(_event, INFINITE);
} }
bool Wait(long milli) {
if(_nowait)
return false;
return WaitForSingleObject(_event, milli + 1) != WAIT_TIMEOUT;
}
void SetNoWait(bool nowait) { void SetNoWait(bool nowait) {
_nowait = nowait; _nowait = nowait;
} }
...@@ -83,6 +88,38 @@ public: ...@@ -83,6 +88,38 @@ public:
_state = false; _state = false;
pthread_mutex_unlock(&_mutex); pthread_mutex_unlock(&_mutex);
} }
bool Wait(long milliseconds)
{
if (_nowait || pthread_mutex_lock(&_mutex) != 0)
return false;
int rc = 0;
struct timespec abstime;
struct timeval tv;
gettimeofday(&tv, NULL);
abstime.tv_sec = tv.tv_sec + milliseconds / 1000;
abstime.tv_nsec = tv.tv_usec*1000 + (milliseconds % 1000)*1000000;
if (abstime.tv_nsec >= 1000000000)
{
abstime.tv_nsec -= 1000000000;
abstime.tv_sec++;
}
while (!_state)
{
if ((rc = pthread_cond_timedwait(&_cond, &_mutex, &abstime)))
{
if (rc == ETIMEDOUT) break;
pthread_mutex_unlock(&_mutex);
return false;
}
}
_state = false;
pthread_mutex_unlock(&_mutex);
return rc == 0;
}
void SetNoWait(bool nowait) { void SetNoWait(bool nowait) {
_nowait = nowait; _nowait = nowait;
} }
......
...@@ -166,11 +166,13 @@ int ReplayMode::ReplayThread(void* param) { ...@@ -166,11 +166,13 @@ int ReplayMode::ReplayThread(void* param) {
mainGame->gMutex.Lock(); mainGame->gMutex.Lock();
mainGame->dInfo.isStarted = false; mainGame->dInfo.isStarted = false;
mainGame->dInfo.isReplay = false; mainGame->dInfo.isReplay = false;
mainGame->CloseDuelWindow(); mainGame->closeDoneSignal.Reset();
mainGame->ClearTextures(); mainGame->closeSignal.Set();
mainGame->closeDoneSignal.Wait();
mainGame->ShowElement(mainGame->wReplay); mainGame->ShowElement(mainGame->wReplay);
mainGame->gMutex.Unlock(); mainGame->gMutex.Unlock();
mainGame->device->setEventReceiver(&mainGame->menuHandler); mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->closeSignal.Set();
} }
return 0; return 0;
} }
......
...@@ -92,11 +92,12 @@ int SingleMode::SinglePlayThread(void* param) { ...@@ -92,11 +92,12 @@ int SingleMode::SinglePlayThread(void* param) {
mainGame->gMutex.Lock(); mainGame->gMutex.Lock();
mainGame->dInfo.isStarted = false; mainGame->dInfo.isStarted = false;
mainGame->dInfo.isSingleMode = false; mainGame->dInfo.isSingleMode = false;
mainGame->CloseDuelWindow(); mainGame->closeDoneSignal.Reset();
mainGame->ClearTextures(); mainGame->closeSignal.Set();
mainGame->closeDoneSignal.Wait();
mainGame->ShowElement(mainGame->wSinglePlay); mainGame->ShowElement(mainGame->wSinglePlay);
mainGame->gMutex.Unlock();
mainGame->device->setEventReceiver(&mainGame->menuHandler); mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->gMutex.Unlock();
} }
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment