5
« 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.