Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Multithreaded rendering in linux  (Read 2406 times)

0 Members and 1 Guest are viewing this topic.

adenosie

  • Newbie
  • *
  • Posts: 1
    • View Profile
Multithreaded rendering in linux
« on: October 13, 2019, 02:36:21 pm »
#include <SFML/Graphics.hpp>
#include <thread>


void render_loop(sf::RenderWindow& window);

int main()
{
    sf::RenderWindow window(sf::VideoMode(1280, 720), sf::String());

    window.setActive(false);
    std::thread render_thread(render_loop, std::ref(window));

    while(window.isOpen())
    {
        sf::Event event;
        while(window.pollEvent(event))
            if(event.type == sf::Event::Closed)
                window.close();

        // update things...
    }
}


void render_loop(sf::RenderWindow& window)
{
    window.setActive(true);

    while(window.isOpen())
    {
        window.clear();
        // draw things...
        window.display();
    }
}
 

It has no problem and compiled well. However when I try to run, an error message comes out:

Quote
[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
XIO:  fatal IO error 0 (Success) on X server ":1"
      after 138 requests (138 known processed) with 0 events remaining.
a.out: xcb_io.c:260: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
Aborted (core dumped)

If I run the same code in windows, it goes well.
And if I add
std::this_thread::sleep_for(1)
before event thread, it goes well too.

 

anything