[SDL] (openGL repaint) thread problem

Johannes Schmidt sdl at myrealbox.com
Thu Aug 9 06:27:01 PDT 2001


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.

After some tests, I think it has something to do with OpenGL.

Consider the following code 
( SDL initialized with SDL_SWSURFACE, next time with SDL_OPENGLBLIT ).

#include "SDL/SDL.h"
#include "SDL/SDL_thread.h"

#include "GL/gl.h"

SDL_Surface * screen;

int draw( void * data) {
    SDL_Rect dstrect = {10, 10, 100, 100 };
    SDL_FillRect(screen, &dstrect, 
                 SDL_MapRGB(screen->format, 0xff, 0x00, 0x00) );
    SDL_UpdateRect(screen,0, 0, 0, 0);
}

int main( int argc, char * argv[] ) {
    SDL_Init(SDL_INIT_VIDEO);
    // if you start the application with an opengl context, it will crash
    // with an Seg fault.
    //screen = SDL_SetVideoMode( 320, 240, 16, SDL_OPENGLBLIT);
    screen = SDL_SetVideoMode( 320, 240, 16, SDL_SWSURFACE);

    SDL_Thread * thr;
    thr = SDL_CreateThread(draw, NULL);
    SDL_WaitThread(thr, NULL);

    SDL_Delay(3000);

    SDL_Quit();

    return 0;
}


Regards,
Johannes




More information about the SDL mailing list