[SDL] Threads and SDL_PollEvent
Pontus Pihlgren
Pontus.Pihlgren.5501 at student.uu.se
Thu Oct 2 04:14:03 PDT 2003
Hey!
I was coding away yesterday and made a multithreaded OpenGL program using SDL.
I set up two threads, the thread where main() is called and a extra thread for
input. The program functions well, it's drawing the 3D stuff I'm expecting and
it receives key events as it should. But the window is not responding to
anything, I cant move, minimize, close or resize it (I'm not sure I should be
able to resize it though). My event polling loop looks (aproximately) like this
while(1){
SDL_Event event;
while( SDL_PollEvent(&event) ){
switch(event.type){
case SDL_KEY:
// handle keystuff and break;
case SDL_QUIT:
// Handle quit event by exit()ing program.
}
}
Scavenging archives, documentation and testing some examples I found out that
if I move the event loop to the main() thread (the thread that called SDL_Init
and SDL_SetVideoMode) then the window is moveable, minimizable and closaable.
So, now everything is tiptop, but as a computer scientist student I get curious
about the tecnical reason for this behaviour. In the docs I've read that
SDL_PollEvent should not be called from "separate" threads... but I'm not sure
what that means. Well, would be fun with an explanation.
Oh yeah, I'm currently coding using Visual Studio .NET under WinXP with SDL
1.2.6, haven't tried it under Linux.
Cya Guys, Popi.
More information about the SDL
mailing list