SFML community forums

Help => Window => Topic started by: dobbi10k on April 29, 2012, 11:17:27 am

Title: Multi-Threaded Event handling
Post by: dobbi10k on April 29, 2012, 11:17:27 am
Hey guys,
I created a MT event handling system for my game engine. Basically in its thread it waits for events and then checks a map whether any part of the game / engine needs to know about the event. If so it pushes the event to the receivers event queu. Sounds great to me, but it doesn't work, unfortunately. It makes the window and hence the app crash, because it 'doesn't respond'... I'm pretty sure this is due to the multi threaded event handling as it works just fine when single threaded (there are other drawbacks, of course). The exact same crash happens when you just leave out the event handling completely. Does anyone have an idea, why Windows doesn't like my way of doing things?

Regards,
dobbi10k
Title: Re: Multi-Threaded Event handling
Post by: Laurent on April 29, 2012, 11:27:54 am
OSes have a restriction: you must handle events in the same thread where the window was created.
Title: Re: Multi-Threaded Event handling
Post by: Nexus on April 29, 2012, 11:42:25 am
By the way, does this restriction only concern the pollEvent() call, or also realtime inputs like sf::Mouse?

Because otherwise, it would be easy to store the events in a queue and react to them in another thread (similar to my ActionMap).
Title: Re: Multi-Threaded Event handling
Post by: Laurent on April 29, 2012, 12:55:20 pm
It's only pollEvent and waitEvent.
Title: Re: Multi-Threaded Event handling
Post by: dobbi10k on April 29, 2012, 01:19:58 pm
Wow, that's a relief... This means I'll only have to cahnge about 5 lines of code :)
And yeah, in that case my system is likely to work as Nexus' :)
Title: Re: Multi-Threaded Event handling
Post by: Hiura on April 29, 2012, 03:41:25 pm
OSes have a restriction: you must handle events in the same thread where the window was created.
On Mac OS X this restriction is stronger : you have to create windows and handle events in the main thread. Unfortunately.