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

Author Topic: 2 windows each with it's own rendering threa  (Read 2034 times)

0 Members and 2 Guests are viewing this topic.

shodan49

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
2 windows each with it's own rendering threa
« on: May 05, 2020, 05:35:53 pm »
what i'm doing should be very simple and yet every time i run this (on linux) i get a different error message, sometimes it runs for a few seconds before becoming unresponsive.

#include <SFML/Window.hpp>
#include <SFML/System.hpp>

class Application
{
public:
    sf::Window *mainWindow;
    sf::Window *debugWindow;
    Application(sf::Window *main, sf::Window *debug)
    {
        mainWindow = main;
        debugWindow = debug;
    }
    void execute()
    {
        while (mainWindow->isOpen())
        {
            // do something...
        }
    }
};
void ThreadA(sf::Window *window)
{
    window->setActive(true);

    while (window->isOpen())
    {
        sf::Event event;
        while (window->pollEvent(event))
            if (event.type == sf::Event::Closed)
                window->close();
        window->display();
    }
}
void ThreadB(sf::Window *window)
{
    window->setActive(true);

    while (window->isOpen())
    {
        sf::Event event;
        while (window->pollEvent(event))
            if (event.type == sf::Event::Closed)
                window->close();
        window->display();
    }
}
int main()
{
    sf::Window mainWindow(sf::VideoMode(1600, 900), "main window");
    sf::Window debugWindow(sf::VideoMode(400, 400), "debug window");
    mainWindow.setActive(false);
    debugWindow.setActive(false);
    Application Application(&mainWindow, &debugWindow);
    sf::Thread mainThread(&ThreadA, &mainWindow);
    mainThread.launch();
    sf::Thread debugThread(&ThreadB, &debugWindow);
    debugThread.launch();
    Application.execute();
    return 0;
}

i followed the tutorials step by step and i can't find what i'm doing wrong.
« Last Edit: May 05, 2020, 05:40:51 pm by shodan49 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: 2 windows each with it's own rendering threa
« Reply #1 on: May 05, 2020, 06:32:17 pm »
Quote
(on linux) i get a different error message
Doesn't it mention the XInitThreads() function?
Laurent Gomila - SFML developer

shodan49

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: 2 windows each with it's own rendering threa
« Reply #2 on: May 05, 2020, 07:13:27 pm »
yes, sometimes is says this:

[xcb] Unknown sequence number while processing reply
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
sfml-app: ../../src/xcb_io.c:641: _XReply: Assertion `!xcb_xlib_threads_sequence_lost' failed.
Aborted (core dumped)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: 2 windows each with it's own rendering threa
« Reply #3 on: May 05, 2020, 09:10:22 pm »
Quote
Most likely this is a multi-threaded client and XInitThreads has not been called
So, call XInitThreads() ;)
Laurent Gomila - SFML developer

shodan49

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: 2 windows each with it's own rendering threa
« Reply #4 on: May 06, 2020, 05:49:24 am »
Quote
Most likely this is a multi-threaded client and XInitThreads has not been called
So, call XInitThreads() ;)

is it a function i have to write in the code or something i have to write in the terminal?

shodan49

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: 2 windows each with it's own rendering threa
« Reply #5 on: May 06, 2020, 06:40:11 am »
ok, XInitThreads(); is a function inside an external library (not SFML).
to install it on linux you need to write: sudo apt install libx11-dev
and then include the header: #include <X11/Xlib.h>

I am now getting an error when i'm trying to link it though...

g++ main.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio -?

what -? do i need to write to do that?
« Last Edit: May 06, 2020, 06:43:09 am by shodan49 »

shodan49

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: 2 windows each with it's own rendering threa
« Reply #6 on: May 06, 2020, 09:31:18 am »
after asking in the discord i discovered you must add -lX11
to link the library.