Listen for events in a thread on Windows

Hi,
I’m writing a little video player with SDL and Ffmpeg. Keyboard and
mouse events are managed
with SDL_WaitEvent() in a thread. My program works fine on Linux, but on
Windows (tested on Windows 2000) it doesn’t work because
it seems that onWindow, all calls to functions like SDL_WaitEvent() or
SDL_PollEvent() have to be made in the main(). Otherwise they will not work.
Is this incorrect? It is possible to listen to events in a thread and
not in main() ?

Thanks for your help.

Hi,
I’m writing a little video player with SDL and Ffmpeg. Keyboard and
mouse events are managed
with SDL_WaitEvent() in a thread. My program works fine on Linux, but on
Windows (tested on Windows 2000) it doesn’t work because
it seems that onWindow, all calls to functions like SDL_WaitEvent() or
SDL_PollEvent() have to be made in the main(). Otherwise they will not
work.
Is this incorrect? It is possible to listen to events in a thread and
not in main() ?

Thanks for your help.

I’m writing a little video player with SDL and Ffmpeg. Keyboard and
mouse events are managed with SDL_WaitEvent() in a thread. My program
works fine on Linux, but on Windows (tested on Windows 2000) it
doesn’t work because it seems that onWindow, all calls to functions
like SDL_WaitEvent() or SDL_PollEvent() have to be made in the main().
Otherwise they will not work. Is this incorrect? It is possible to
listen to events in a thread and not in main() ?

Yes, SDL_WaitEvent() calls SDL_PumpEvents(), which can only be called
from the thread that initialized SDL. You can, however, call
SDL_PeekEvents() from any thread you like, though you’ll need to be sure
to occasionally call SDL_PumpEvents() from your SDL_Init-ing thread so
the events will actually get to it.

You can actually see how to do this quite easilly if you look at the
code for SDL_WaitEvent() for example.

I ran into this exact problem when coding a multithreaded app in SDL the
first time - is this in a FAQ? If not, shouldn’t it be?On Wed, May 11, 2005 at 03:18:07PM +0200, Claude Joseph-Angelique wrote:


Steaphan Greene
GPG public key: http://www.cs.binghamton.edu/~sgreene/gpg.key.txt
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050511/73b17984/attachment.pgp

Steaphan Greene wrote:>On Wed, May 11, 2005 at 03:18:07PM +0200, Claude Joseph-Angelique wrote:

I’m writing a little video player with SDL and Ffmpeg. Keyboard and
mouse events are managed with SDL_WaitEvent() in a thread. My program
works fine on Linux, but on Windows (tested on Windows 2000) it
doesn’t work because it seems that onWindow, all calls to functions
like SDL_WaitEvent() or SDL_PollEvent() have to be made in the main().
Otherwise they will not work. Is this incorrect? It is possible to
listen to events in a thread and not in main() ?

Yes, SDL_WaitEvent() calls SDL_PumpEvents(), which can only be called
from the thread that initialized SDL.

Ok, thanks.
I ask me why puting SDL_WaitEvent() and SDL_Init() in separate threads
is allowed on Linux and
not on Windows.

It’s my understanding that it is NOT allowed in either, it just happens
to usually work (though not for some events, like window resize events)
in Linux, and not in Windows.On Thu, May 12, 2005 at 10:48:36AM +0200, Claude Joseph-Angelique wrote:

I ask me why puting SDL_WaitEvent() and SDL_Init() in separate threads
is allowed on Linux and not on Windows.


Steaphan Greene
GPG public key: http://www.cs.binghamton.edu/~sgreene/gpg.key.txt
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050512/c052e846/attachment.pgp

I ask me why puting SDL_WaitEvent() and SDL_Init() in separate threads
is allowed on Linux and not on Windows.

It’s my understanding that it is NOT allowed in either, it just happens
to usually work (though not for some events, like window resize events)
in Linux, and not in Windows.

That is correct. You aren’t supposed to do that on either platform and
there are other platforms where it may or may not work.

So, why does it work on Linux and not on Windows? Why does my net2
library run faster on a 500mhz Linux box than on a multigigahertz
Windows XP box? Can I answer that question without starting a flame
war? ;} I don’t think so!

Windows has its limitations. Linux has its limitations. The one thing
you can be sure of is that they are very different systems. To use an
old Americanism, would you expect Chevy parts to work right in a Ford?

	Bob PendletonOn Thu, 2005-05-12 at 05:23 -0400, Steaphan Greene wrote:

On Thu, May 12, 2005 at 10:48:36AM +0200, Claude Joseph-Angelique wrote:


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

±-------------------------------------+