No events on threaded window

Hi there, this is my first post and would consider myself a beginner
on SDL. I would like to put a sdl window on a separate thread. I have
made that happen but unfortunately the window doesn’t seems to receive
any events. The rendering ( a basic animation ) just runs fine.

I’m using sdl 1.2.11 on windows xp. My basic design looks like as
follows. I have a main thread which is a console application. Here I’m
initializing SDL and create a screen using SDL_SetVideoMode. When this
is done I spawn a new thread where I would render into the screen.
Meaning the event loop is inside this separate thread.

Can anybody tell my why my window doesn’t receive any events?

Thanks ahead,
Christian

Alright I figured it out. I need to move my event loop out of the
thread and put it in the main thread. That means in my case inside the
main(). Does that mean I can only have one loop? What about when I
have more than one window. Which is actually my goal. Is that
considered or supoorted by the design of SDL?

If my use case is too confusing please let me know.

ChristianOn 5/15/07, Christian Henning <@Christian_Henning> wrote:

Hi there, this is my first post and would consider myself a beginner
on SDL. I would like to put a sdl window on a separate thread. I have
made that happen but unfortunately the window doesn’t seems to receive
any events. The rendering ( a basic animation ) just runs fine.

I’m using sdl 1.2.11 on windows xp. My basic design looks like as
follows. I have a main thread which is a console application. Here I’m
initializing SDL and create a screen using SDL_SetVideoMode. When this
is done I spawn a new thread where I would render into the screen.
Meaning the event loop is inside this separate thread.

Can anybody tell my why my window doesn’t receive any events?

Thanks ahead,
Christian

Christian,

I found this out after a significant amount of design along these same
lines. A good approach might be to have a “master” event loop in the
main thread that picks up these events, and then have that main loop
dispatch new events (via roll-your-own message system, or use an
existing message-passing API) to the target threads.On Tue, 2007-05-15 at 21:46 -0400, Christian Henning wrote:

Alright I figured it out. I need to move my event loop out of the
thread and put it in the main thread. That means in my case inside the
main(). Does that mean I can only have one loop? What about when I
have more than one window. Which is actually my goal. Is that
considered or supoorted by the design of SDL?

If my use case is too confusing please let me know.

Christian


Coleman Kane

On 5/15/07, Christian Henning wrote:

Hi there, this is my first post and would consider myself a beginner
on SDL. I would like to put a sdl window on a separate thread. I have
made that happen but unfortunately the window doesn’t seems to receive
any events. The rendering ( a basic animation ) just runs fine.

I’m using sdl 1.2.11 on windows xp. My basic design looks like as
follows. I have a main thread which is a console application. Here I’m
initializing SDL and create a screen using SDL_SetVideoMode. When this
is done I spawn a new thread where I would render into the screen.
Meaning the event loop is inside this separate thread.

Can anybody tell my why my window doesn’t receive any events?

Thanks ahead,
Christian


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I was thinking of creating a sdl_service class with a run() method
containing the event loop. Something like:

int main()
{
sdl_service ss;

// init windows and store them in ss

ss.run();

return 0;
}

But do you know how I can figure out the window from an event? I just
glanced over the event structure and couldn’t find it.

Thanks for you insight.

ChristianOn 5/16/07, Coleman Kane wrote:

On Tue, 2007-05-15 at 21:46 -0400, Christian Henning wrote:

Alright I figured it out. I need to move my event loop out of the
thread and put it in the main thread. That means in my case inside the
main(). Does that mean I can only have one loop? What about when I
have more than one window. Which is actually my goal. Is that
considered or supoorted by the design of SDL?

If my use case is too confusing please let me know.

Christian

Christian,

I found this out after a significant amount of design along these same
lines. A good approach might be to have a “master” event loop in the
main thread that picks up these events, and then have that main loop
dispatch new events (via roll-your-own message system, or use an
existing message-passing API) to the target threads.

Alright I figured it out. I need to move my event loop out of the
thread and put it in the main thread. That means in my case inside the
main(). Does that mean I can only have one loop? What about when I
have more than one window. Which is actually my goal. Is that
considered or supoorted by the design of SDL?

If my use case is too confusing please let me know.

Christian

Christian,

I found this out after a significant amount of design along these same
lines. A good approach might be to have a “master” event loop in the
main thread that picks up these events, and then have that main loop
dispatch new events (via roll-your-own message system, or use an
existing message-passing API) to the target threads.

I was thinking of creating a sdl_service class with a run() method
containing the event loop. Something like:

int main()
{
sdl_service ss;

// init windows and store them in ss

ss.run();

return 0;
}

But do you know how I can figure out the window from an event? I just
glanced over the event structure and couldn’t find it.

SDL itself doesn’t actually do any window management. There are some
hooks on some architectures that allow you access to the window-manager
data structure passed with many window events.

I don’t even know if its possible to have two SDL "graphical windows"
from the same application. That’s not a configuration that I’ve tried.
If you’ve already got multiple SDL windows I’d like to know how you did
it.On Wed, 2007-05-16 at 10:14 -0400, Christian Henning wrote:

On 5/16/07, Coleman Kane <@Coleman_Kane> wrote:

On Tue, 2007-05-15 at 21:46 -0400, Christian Henning wrote:

Thanks for you insight.

Christian

Hello !

I don’t even know if its possible to have two SDL "graphical windows"
from the same application. That’s not a configuration that I’ve tried.
If you’ve already got multiple SDL windows I’d like to know how you did
it.

With SDL 1.2 only it is not possible to get multiple windows.
With SDL 1.3/2.0 it is. You can find some hacks on the net
how to get multiple windows on different OSes. But these hacks
are not really portable.

If you don’t need 100% speed, i would use a GUI toolkit like
GTK, FLTK and use SDL as a composing engine only.

CU

Thanks Torsten. How far is sdl 1.3? Is it usable already?

ChristianOn 5/16/07, Torsten Giebl wrote:

Hello !

I don’t even know if its possible to have two SDL "graphical windows"
from the same application. That’s not a configuration that I’ve tried.
If you’ve already got multiple SDL windows I’d like to know how you did
it.

With SDL 1.2 only it is not possible to get multiple windows.
With SDL 1.3/2.0 it is. You can find some hacks on the net
how to get multiple windows on different OSes. But these hacks
are not really portable.

If you don’t need 100% speed, i would use a GUI toolkit like
GTK, FLTK and use SDL as a composing engine only.

CU


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hello !

Thanks Torsten. How far is sdl 1.3? Is it usable already?

Try it out yourself :

http://www.libsdl.org/svn.php

CU

Christian scrisse:

I was thinking of creating a sdl_service class with a run() method
containing the event loop. Something like:

int main()
{
sdl_service ss;

// init windows and store them in ss

ss.run();

return 0;
}

That’s a great idea, but your app won’t link. SDL uses a macro to fool
with the main entry point, so you need to declare your main as

int main(int argc, char *argv[]);

Of course if your other services have similar tastes then the number
of services you can offer will be limited to just one. Perhaps it would
be better to call it “the_sdl_service” to communicate its uniqueness.

RF–
felix: lightweight threads, HOFs and game scripting.
svn co https://svn.sourceforge.net/svnroot/felix/felix/trunk felix

Alright, I take that invitation. I have grabbed the latest and
greatest from svn head. Obviously I need to compile it myself. In
doing so I tried using the vc project for VC7.1 which seems totally
outdated. There are files to compile that do not exist anymore and
there aren’t files included that should be compiled. I don’t mind
creating a more updated version if there is interest in that. Could
anybody please tell me what .c files need to included? All of them
plus the platform specifics, I guess. Is there an easy way to
determine that?

Also there is compilation error in SDL_audiocvt.c . The stdio.h header
is missing.

ChristianOn 5/16/07, Torsten Giebl wrote:

Hello !

Thanks Torsten. How far is sdl 1.3? Is it usable already?

Try it out yourself :

http://www.libsdl.org/svn.php

CU


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org