I'm trying to use SFML 2.1 for a small simple project, and want to have the renderer and the event loop in different threads. However it doesn't seem to be possible, as the program either crashes (segmentation fault) or get some X11 error:
XIO: fatal IO error 11 (Resource temporarily unavailable) on X server ":0"
after 106 requests (106 known processed) with 0 events remaining.
My test program is about the simplest possible:
#include <iostream>
#include <thread>
#include <SFML/Window.hpp>
namespace
{
void renderer(sf::Window& window)
{
window.setActive(true);
while (window.isOpen())
{
window.display();
}
}
}
int main()
{
sf::Window window(sf::VideoMode(1280, 800), "Testing",
sf::Style::Default, sf::ContextSettings(32));
window.setActive(false);
std::thread render_thread{renderer, std::ref(window)};
while (window.isOpen())
{
sf::Event event;
while (window.isOpen() && window.pollEvent(event))
{
}
}
render_thread.join();
}
Is there a way to run the rendering and event loop from different threads using SFML 2? I tried a similarly simple program using SDL2 and it works okay.