PDA

View Full Version : Multi-threaded GL Crash



jtipton
04-23-2008, 02:04 PM
I have the following application that attempts to perform multi-threaded rendering inside a glut application. Any ideas on why this crashes?




#include <X11/Xlib.h> // for XInitThreads() call
#include <GL/glut.h> // GL Utility Toolkit
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>

boost::mutex gdmutex;

void display(void)
{
boost::mutex::scoped_lock lock(gdmutex);

glClear(GL_COLOR_BUFFER_BIT);
glutSolidTetrahedron();
glutSwapBuffers();
}

void render(void)
{
while(true) { display(); }
}

void visible(int state)
{
static bool once(false);

if(!once) { boost::thread rthread(&amp;render); }

once = true;
}

int main(int argc, char* argv[])
{
XInitThreads();

glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_DOUBLE);
glutCreateWindow("Sample");

glutDisplayFunc(display);
glutVisibilityFunc(visible);

glutMainLoop();

return 0;
}

jtipton
04-23-2008, 02:08 PM
Is there a makeCurrent concept in GLUT? That is the only thing I notice.

Zengar
04-23-2008, 04:15 PM
All GL commands have to be issued within the thread that hold the GL context current. With other words, you can't split GL commands across different threads. With even other words, you have to use the default thread (the thread that initialized and created your glut window) as your rendering thread.

Lindley
04-24-2008, 10:25 AM
Is there a makeCurrent concept in GLUT? That is the only thing I notice.

No. GLUT is a beginner's tool, it shouldn't be used for anything relatively advanced.