Maybe I should try that solution... I actually pause the thread by using a condition variable and before blocking, the render thread calls an "onPause" function which deactivates the window. (Pausing and unpausing by itself works... but recreating the window crashes with all kinds of strangeness...
Modified GameTask:
void GameTask::run()
{
running = true;
paused = false;
init();
while(running)
{
{
boost::unique_lock<boost::mutex> lock(pauseMutex);
bool first = true;
while(paused)
{
if(first)
{
first = false;
onPause(true);
}
pauseCond.notify_all();
pauseCond.wait(lock);
}
if(!first)
onPause(false);
}
loopBody();
executeCalls();
}
fini();
}
void GameTask::pause(bool pause)
{
if(pause && !paused)
{
boost::unique_lock<boost::mutex> lock(pauseMutex);
paused = true;
pauseCond.wait(lock); // wait until the task is actually paused
}
else if(!pause && paused)
{
{
boost::lock_guard<boost::mutex> lock(pauseMutex);
paused = false;
}
pauseCond.notify_all();
}
}
onPause function for Renderer:
void onPause(bool paused)
{
window->SetActive(!paused);
if(!paused)
{
// Set color and depth clear value
glClearDepth(1.f);
glClearColor(0.f, 0.f, 0.f, 0.f);
// Enable Z-buffer read and write
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
// Setup a perspective projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.f, (float)window->GetWidth()/(float)window->GetHeight(), 1.f, 500.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
}