New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Window::waitEvent does not return when window is closed #1184
Comments
We like to discuss unconfirmed issues and design questions (like this one here) on the forum as stated in the contribution guidelines. While I at first thought that this might need adjustments to the documented or adding your suggested Sure, if you close the window, ignore the close event and then call A similar situation can be constructed for My conclusion It's working as intended (test for the window re-creation situation is needed) and if you get stuck in an infinite loop, it's a programming error that can easily be prevented. |
AFAIK the problem is that the queue gets freed upon closing the window, therefore the time window for When the window has been closed and the thread is inside |
SFML classes are not thread-safe (and I hope it is documented properly). So you have to take care of concurrent access, such as closing a window from one thread while the other thread is processing events. Maybe sf::Window could be made thread-safe, since if you use threads, it will most likely involve this class. But to be 100% safe, it may require a lot of work and we have to evaluate the performance cost. |
Okay with that view, things seem to look different. (Maybe next time provide the real problem first 😉).
I so far never questioned it, but does SFML's implementation guarantee that the close event will always be triggered before the If that guarantee is not given, then there's nothing a user can do, to make the use of
The next question would then be, if |
Since waitEvent() is blocking, there's nothing a user can do. The typical solution would be to do like SFML does internally: call pollEvent in a loop with a small sleep between each itreation. From there you can use synchronization primitives (like mutexes) to protect things. But I agree that something should be done internally to avoid this kind of issue. |
What's the use case then for The only time you can use The only other use case I can kind of think of, is an application that is purely based on waiting for events. So it only does something if there are events. Which seems like a really odd use case. With that in mind, I feel we should make it possible for |
The only reason I can can see right now why it can't be safely used in a multi-threaded environment is because we manage events using our own additional event queue. If we didn't have to periodically take care of sensors and joysticks we could block on the OS and not have to care. Mixing joystick/sensor handling with OS window event handling is something that could be separated in the future. It is an unnecessary burden that we put on users who don't intend to make use of those features.
Or... if we sent out a "loopback event" on Window::close() that triggers the OS to send some kind of event. Other libraries have support for sending custom OS events, among other reasons for cases like this.
In fact... at work I had to write among other things a GUI frontend for industrial machine control that would run with minimal resources on an embedded platform (RPi CM). It would draw the user interface and wait for user input or some other GUI-changing event to occur before proceeding with the next iteration through the main loop. I used GLFW (needed robust OpenGL ES 2.0 support and I used raw OpenGL all over the place anyway) and ended up just using glfwWaitEvents() and glfwPostEmptyEvent() for this. It ended up in a clean, very light-weight (0% CPU/GPU in over 99% of the time) and satisfactory solution.
I think the main problem right now is firstly that |
I added some labels but I'm not really sure where we ended up with the discussion.
Do we do something about this or do we just mark it as "won't fix"? |
Description
Window::waitEvent does not return after Window::close is called, which causes the eventual dedicated event thread to wait for an event that will never arrive.
Solution
The text was updated successfully, but these errors were encountered: