Commit e9dfbcc9 authored by Soar Qin's avatar Soar Qin

Resolved the crash problem under posix due to run glGenTextures and...

Resolved the crash problem under posix due to run glGenTextures and glDeleteTextures in different threads
parent cdcd1e37
......@@ -159,7 +159,9 @@ void DuelClient::ClientEvent(bufferevent *bev, short events, void *ctx) {
mainGame->btnCreateHost->setEnabled(true);
mainGame->btnJoinHost->setEnabled(true);
mainGame->btnJoinCancel->setEnabled(true);
mainGame->CloseDuelWindow();
mainGame->closeDoneSignal.Reset();
mainGame->closeSignal.Set();
mainGame->closeDoneSignal.Wait();
mainGame->dInfo.isStarted = false;
mainGame->is_building = false;
mainGame->device->setEventReceiver(&mainGame->menuHandler);
......@@ -498,7 +500,9 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
mainGame->actionSignal.Reset();
mainGame->actionSignal.Wait();
mainGame->gMutex.Lock();
mainGame->CloseDuelWindow();
mainGame->closeDoneSignal.Reset();
mainGame->closeSignal.Set();
mainGame->closeDoneSignal.Wait();
mainGame->dInfo.isStarted = false;
mainGame->btnCreateHost->setEnabled(true);
mainGame->btnJoinHost->setEnabled(true);
......@@ -701,7 +705,9 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
mainGame->actionSignal.Reset();
mainGame->actionSignal.Wait();
mainGame->gMutex.Lock();
mainGame->CloseDuelWindow();
mainGame->closeDoneSignal.Reset();
mainGame->closeSignal.Set();
mainGame->closeDoneSignal.Wait();
mainGame->dInfo.isStarted = false;
mainGame->btnCreateHost->setEnabled(true);
mainGame->btnJoinHost->setEnabled(true);
......
......@@ -100,7 +100,6 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
}
if(mainGame->dInfo.player_type == 7) {
DuelClient::StopClient();
mainGame->CloseDuelWindow();
mainGame->dInfo.isStarted = false;
mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->btnCreateHost->setEnabled(true);
......
......@@ -541,6 +541,8 @@ void Game::MainLoop() {
}
}
driver->endScene();
if(closeSignal.Wait(0))
CloseDuelWindow();
fps++;
cur_time = timer->getTime();
if(cur_time < fps * 17 - 20)
......@@ -905,6 +907,7 @@ void Game::CloseDuelWindow() {
lstHostList->clear();
DuelClient::hosts.clear();
ClearTextures();
closeDoneSignal.Set();
}
int Game::LocalPlayer(int player) {
return dInfo.isFirst ? player : 1 - player;
......
......@@ -102,6 +102,8 @@ public:
Signal actionSignal;
Signal replaySignal;
Signal singleSignal;
Signal closeSignal;
Signal closeDoneSignal;
Config gameConf;
DuelInfo dInfo;
......
......@@ -25,6 +25,11 @@ public:
return;
WaitForSingleObject(_event, INFINITE);
}
bool Wait(long milli) {
if(_nowait)
return false;
return WaitForSingleObject(_event, milli + 1) != WAIT_TIMEOUT;
}
void SetNoWait(bool nowait) {
_nowait = nowait;
}
......@@ -83,6 +88,38 @@ public:
_state = false;
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) {
_nowait = nowait;
}
......
......@@ -166,11 +166,13 @@ int ReplayMode::ReplayThread(void* param) {
mainGame->gMutex.Lock();
mainGame->dInfo.isStarted = false;
mainGame->dInfo.isReplay = false;
mainGame->CloseDuelWindow();
mainGame->ClearTextures();
mainGame->closeDoneSignal.Reset();
mainGame->closeSignal.Set();
mainGame->closeDoneSignal.Wait();
mainGame->ShowElement(mainGame->wReplay);
mainGame->gMutex.Unlock();
mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->closeSignal.Set();
}
return 0;
}
......
......@@ -92,11 +92,12 @@ int SingleMode::SinglePlayThread(void* param) {
mainGame->gMutex.Lock();
mainGame->dInfo.isStarted = false;
mainGame->dInfo.isSingleMode = false;
mainGame->CloseDuelWindow();
mainGame->ClearTextures();
mainGame->closeDoneSignal.Reset();
mainGame->closeSignal.Set();
mainGame->closeDoneSignal.Wait();
mainGame->ShowElement(mainGame->wSinglePlay);
mainGame->gMutex.Unlock();
mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->gMutex.Unlock();
}
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