Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Multi-Threaded Event handling  (Read 3477 times)

0 Members and 2 Guests are viewing this topic.

dobbi10k

  • Newbie
  • *
  • Posts: 14
    • View Profile
Multi-Threaded Event handling
« 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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Multi-Threaded Event handling
« Reply #1 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.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Multi-Threaded Event handling
« Reply #2 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).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Multi-Threaded Event handling
« Reply #3 on: April 29, 2012, 12:55:20 pm »
It's only pollEvent and waitEvent.
Laurent Gomila - SFML developer

dobbi10k

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Multi-Threaded Event handling
« Reply #4 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' :)

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Multi-Threaded Event handling
« Reply #5 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.
SFML / OS X developer