1
System / Problem with threads on Linux
« on: July 15, 2017, 03:46:05 pm »
I am trying to separate the event thread and the rendering thread in my game.
To try it out, I ran the following code from the SFML tutorials :
However, after compiling and running this program, I get this error :
I read in this topic that this problem can be solved by calling XInitThreads(), but that it is a bad solution, because not only is it not cross-platform, but it adds overhead and might slow down everything.
It is explicitly stated in the tutorials to manage events in the main thread, which is the case here, so I think it is a bit misleading to promote a solution that is not cross platform in the tutorials.
I also tested it with std::thread and i get the same results.
I sometimes get this error message repeated multiple times : `Error while creating udev enumerator`, so I believe the problem comes from SFML.
For information, my OS is manjaro Linux, and I use SFML 2.4.2.
To try it out, I ran the following code from the SFML tutorials :
void renderingThread(sf::RenderWindow* window)
{
// the rendering loop
while (window->isOpen())
{
// draw...
// end the current frame
window->display();
}
}
int main()
{
// create the window (remember: it's safer to create it in the main thread due to OS limitations)
sf::RenderWindow window(sf::VideoMode(800, 600), "OpenGL");
// deactivate its OpenGL context
window.setActive(false);
// launch the rendering thread
sf::Thread thread(&renderingThread, &window);
thread.launch();
// the event/logic/whatever loop
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) window.close();
}
}
return 0;
}
{
// the rendering loop
while (window->isOpen())
{
// draw...
// end the current frame
window->display();
}
}
int main()
{
// create the window (remember: it's safer to create it in the main thread due to OS limitations)
sf::RenderWindow window(sf::VideoMode(800, 600), "OpenGL");
// deactivate its OpenGL context
window.setActive(false);
// launch the rendering thread
sf::Thread thread(&renderingThread, &window);
thread.launch();
// the event/logic/whatever loop
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) window.close();
}
}
return 0;
}
However, after compiling and running this program, I get this error :
Code: [Select]
[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
test: xcb_io.c:165: dequeue_pending_request: Assertion `!xcb_xlib_unknown_req_in_deq' failed.
Aborted (core dumped)
I read in this topic that this problem can be solved by calling XInitThreads(), but that it is a bad solution, because not only is it not cross-platform, but it adds overhead and might slow down everything.
It is explicitly stated in the tutorials to manage events in the main thread, which is the case here, so I think it is a bit misleading to promote a solution that is not cross platform in the tutorials.
I also tested it with std::thread and i get the same results.
I sometimes get this error message repeated multiple times : `Error while creating udev enumerator`, so I believe the problem comes from SFML.
For information, my OS is manjaro Linux, and I use SFML 2.4.2.