According to the documentation, “You can only call [SDL_PumpEvents()] in
the thread that set the video mode.” In fact, SDL_PumpEvents() seems to be
dependent on SDL_Init(), rather than SDL_SetVideoMode().
The following program (shortened as much as possible) displays a window for
five seconds:
#include “SDL.h” #include “SDL_thread.h” #undef main
According to the documentation, “You can only call [SDL_PumpEvents()] in
the thread that set the video mode.” In fact, SDL_PumpEvents() seems to be
dependent on SDL_Init(), rather than SDL_SetVideoMode().
The following program (shortened as much as possible) displays a window for
five seconds:
[snipped]
Is this a question or a statement?
Your program will run just fine, but it won’t actually get any events.
SDL doesn’t crash if you call SDL_PumpEvents() in another thread, it
just won’t do anything.
See ya!
-Sam Lantinga, Software Engineer, Blizzard Entertainment
According to the documentation, “You can only call [SDL_PumpEvents()] in
the thread that set the video mode.” In fact, SDL_PumpEvents() seems
to be
dependent on SDL_Init(), rather than SDL_SetVideoMode().
The following program (shortened as much as possible) displays a window
for
five seconds:
[snipped]
Is this a question or a statement?
Yes.
Your program will run just fine, but it won’t actually get any events.
SDL doesn’t crash if you call SDL_PumpEvents() in another thread, it
just won’t do anything.
I changed the PumpEvents() call to PollEvent() and it handles an SDL_QUIT
event fine. Is there, in fact, any dependency on SetVideoMode(), or can I
safely leave the event loop in its own thread?
I changed the PumpEvents() call to PollEvent() and it handles an SDL_QUIT
event fine. Is there, in fact, any dependency on SetVideoMode(), or can I
safely leave the event loop in its own thread?
Aye, you can run it in its own thread, but you will need to call
SDL_PumpEvents() from the main thread (I’m not sure if it needs to be the
initial thread, or the thread that called SDL_SetVideoMode(); Sam?) for that
thread to actually get any events. I might be wrong, but I believe thats
the only actual use for SDL_PumpEvents
().
Alex Lyman (“Silicon”) is the Lead Programmer,
among other things, for LAO Gaming.
Alex also is a Web Designer/Programmer in his
spare time. If you need a website designed,
or just need programming done for one, contact
him at AlexLyman at Earthlink.net
=cut
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.594 / Virus Database: 377 - Release Date: 2/24/2004
----- Original Message -----
From: willeke@users.sourceforge.net (Jon Willeke)
To:
Sent: Sunday, February 29, 2004 6:59 PM
Subject: Re: [SDL] processing events in a thread
According to the documentation, “You can only call [SDL_PumpEvents()] in
the thread that set the video mode.” In fact, SDL_PumpEvents() seems to be
dependent on SDL_Init(), rather than SDL_SetVideoMode().
The following program (shortened as much as possible) displays a window for
five seconds:
Were you asking a question or trying to make a point? If so, please be
more specific because I can’t figure out what you are trying to say.
BTW, the listed code will wait for 5 seconds, but it will not properly
handle input events because you are calling pollevent in the wrong
thread. If you take 10 minutes to look at the SDL code you will find
that what you are doing is not thread safe.
Bob PendletonOn Sat, 2004-02-28 at 16:13, Jon Willeke wrote:
#include “SDL.h” #include “SDL_thread.h” #undef main
At 3/1/2004, Bob Pendleton wrote:>On Sat, 2004-02-28 at 16:13, Jon Willeke wrote:
According to the documentation, “You can only call [SDL_PumpEvents()] in
the thread that set the video mode.” In fact, SDL_PumpEvents() seems
to be
dependent on SDL_Init(), rather than SDL_SetVideoMode().
Were you asking a question or trying to make a point? If so, please be
more specific because I can’t figure out what you are trying to say.
BTW, the listed code will wait for 5 seconds, but it will not properly
handle input events because you are calling pollevent in the wrong
thread. If you take 10 minutes to look at the SDL code you will find
that what you are doing is not thread safe.
I was asking whether the stated dependency was correct, because my testing
appeared to contradict it. PumpEvents() works fine in a thread separate
from SetVideoMode() and PollEvent() can handle a QUIT event. On further
testing I discovered, as you point out, that it could not handle a KEYDOWN
event unless I moved SetVideoMode() into the event loop thread (or vice versa).
Hi only want to expres what i have done…
Months ago with out knoing nothing about side effects between threads
and event catchin i made a little demo of arcanoid
In my game code i was using SDL_WaitEvent() in a second thread and the
program runs as i’d espected, chatching all the keboard events.
This is an snip of my code
class Teclado : public Colector {
friend int LeerTeclado(void *);
public:
Teclado ();
~Teclado ();
void update();
private:
SDL_Thread *teclado;
int mover;
int disparar;
int salir;
};