Using Thread to pass SFML Render Window

  c++, sfml

I want to handle events in second thread but it shows some debug error.[Error code 3]. Any reason isn’t specified

#include<SFML/Graphics.hpp>
#include<thread>
void EventsHandler(sf::RenderWindow* window) {
    sf::Event evt;
    while (window->pollEvent(evt))
        if (evt.type == 0)
            window->close();
}

int main() {
    sf::RenderWindow window(sf::VideoMode(200, 200), "Tutorials");
    while (window.isOpen())
    {
        std::thread EventHandle(EventsHandler, &window);
        window.clear();
        window.display();
    }

}

I also tried by passing with reference i.e
the parameter of EventsHandler is RenderWindows& and in thread is use std::ref but same result.

Source: Windows Questions C++

LEAVE A COMMENT