SFML community forums
Help => General => Topic started by: BlueX on October 25, 2013, 01:46:54 am
-
Hello,
I'm creating a game and i create a thread to handle all events in the game, but the problem is that when i use the thread my aplications freezes and crash, i runed a debug and i figured that the problem was with the thread. so i did this:
//events_thread.launch();
But it still crashing, so i realise that i need to use the event loop in the main fuction, which is game_start.
So my question is why i can't use a event thread? And how much threads can i create?
Thanks.
Here is the code expleined:
-
The code's missing.
-
To quote from the official tutorial (http://www.sfml-dev.org/tutorials/2.1/window-window.php).
Events must be polled in the window's thread
This is an important limitation of most OSes: the event loop (more precisely, the pollEvent or waitEvent function) must be called in the same thread that created the window. This means that if you want to create a dedicated thread for event handling, you'll have to make sure that the window is created in this thread too. If you really want to split things between threads, it is more convient to keep event handling in the main thread and move the rest (rendering, physics, logic, ...) to a separate thread instead. This configuration will also be compatible with the other limitation described below.
-
The code's missing.
There is no need to show the code, i explained everything...
To quote from the official tutorial (http://www.sfml-dev.org/tutorials/2.1/window-window.php).
Events must be polled in the window's thread
This is an important limitation of most OSes: the event loop (more precisely, the pollEvent or waitEvent function) must be called in the same thread that created the window. This means that if you want to create a dedicated thread for event handling, you'll have to make sure that the window is created in this thread too. If you really want to split things between threads, it is more convient to keep event handling in the main thread and move the rest (rendering, physics, logic, ...) to a separate thread instead. This configuration will also be compatible with the other limitation described below.
Thanks i didn't see that in sfml tutorial, thanks a lot :D