Hi,
the code works, it's just that the return code is weird:
#include <SFML/Graphics.hpp>
sf::RenderWindow wnd;
void sig()
{
wnd.setActive(true);
wnd.clear(sf::Color::Green);
wnd.display();
wnd.setActive(false);
}
int main()
{
wnd.create(sf::VideoMode(800, 600, 32), "Title", sf::Style::Default);
wnd.setActive(false);
sf::Thread ap(sig);
ap.launch();
ap.wait();
return 0;
}
This is a minimal example, and it returns 234, or 0xEA in hex.
#include <SFML/Graphics.hpp>
sf::RenderWindow wnd;
void sig()
{
wnd.setActive(true);
wnd.clear(sf::Color::Green);
wnd.display();
}
int main()
{
wnd.create(sf::VideoMode(800, 600, 32), "Title", sf::Style::Default);
wnd.setActive(false);
sf::Thread ap(sig);
ap.launch();
ap.wait();
return 0;
}
Will cause a segmentation fault and return 139 (0x8B).
What am I doing wrong?
No, not a single instance is global.
#include <SFML/Graphics.hpp>
class Draw
{
public:
Draw()
{
}
void start()
{
thr = new sf::Thread(&Draw::drawer, this);
thr->launch();
}
void setWindow(sf::RenderWindow *wind)
{
wnd = wind;
}
private:
void drawer()
{
wnd->setActive(true);
wnd->clear(sf::Color::Green);
wnd->display();
wnd->setActive(false);
}
sf::Thread *thr;
sf::RenderWindow *wnd;
};
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600, 32), "Title", sf::Style::Default);
Draw object;
window.setActive(false);
object.setWindow(&window);
object.start();
sf::sleep(sf::seconds(2)); // So the thread can finish in peace.
return 0;
}
returns 234.