[SDL] (openGL repaint) thread problem

Johann Deneux johannd at DoCS.UU.SE
Fri Aug 10 06:22:01 PDT 2001


On Wed, 8 Aug 2001, Johannes Schmidt wrote:

> 
> On Tuesday 07 August 2001 21:30, Johann Deneux wrote:
> > > I have some problems using threads.
> > >
> > > If I try to do some drawing stuff in a thread created with
> > > SDL_CreateThread, the application exits with
> > > Fatal signal: Segmentation Fault (SDL Parachute Deployed)
> > > Xlib: unexpected async reply (sequence 0x66)!
> >
> > Your X server does not support multi-threading. You have to do all your
> > calls to the Xlib from one single thread. I guess you may even have to use
> > only the main thread.
> 
> That seems to be reasonable.

I know for sure using threads with the Xlib is in general dangerous. That
means using anything that uses the Xlib is trickt too: Qt, gtk, OpenGL,
SDL...

> I have tried to compile the code under windows( mingw32 ) and it works.
> Also, I packed all graphic things into one repaint function and created a
> thread out of it. That works, too.
> 
> example:
> int paintThread(void * data) {
>     SDL_SetVideoMode( 320, 240, 32, SDL_OPENGL);
> 
>     glViewport(0, 0, 320, 240);
>     glMatrixMode(GL_PROJECTION);
>     glLoadIdentity();
>     glOrtho( 0, 320, 0, 240, -1, 1);
> 
>     glMatrixMode(GL_MODELVIEW);
>     glLoadIdentity();
> 
>     while(!quitThread) {
>         glClear( GL_COLOR_BUFFER_BIT );
>         glLoadIdentity();
> 
>         glBegin( GL_QUADS );
>         glVertex2i(10, 10);
>         glVertex2i(10, 100);
>         glVertex2i(100, 100);
>         glVertex2i(100, 10);
>         glEnd();
> 
>         SDL_GL_SwapBuffers();
>     }
>     return -1;
> }
> 
> But it is a bit unhandy to have all paint things in one thread.
> 
> Is this a general problem of X servers or just of mine ( XFree86 4.1 )?

It is a general "problem".

> Which X servers are multi-threaded?

I know XFree 3 could be compiled with threads support. But even then, you
would need to use some macros or functions (whose names I forgot) to
peform locking/unlocking. Anyway, you probably do not want to force your
users to recompile their X Server, do you ?

I don't really see why you want to use a thread to paint. As soon
as another threads tries to read events, your application may crash. My
advice is: avoid threads in this kind of situation.

-- 
Johann Deneux
http://www.esil.univ-mrs.fr/~jdeneux/projects/





More information about the SDL mailing list