Hi everyone, I'm experiencing a weird bug with std::thread and SFML, and I couldn't find any answer in this forum / google / stackoverflow :
When I run the piece of code that I attached at the end of this post, I get a "Segmentation fault" on the
t.join(); instruction.
However, if I delete everything about SFML, returning EXIT_SUCCESS right after the t.join();, the program exits without error.
I'm using Windows Code::Blocks IDE loaded with TDM-gcc builder (codeblocks-13.12, mingw-TDM-GCC-481), and I installed SFML 2.1 (SFML-2.1-windows-gcc-4.7-tdm-32bits). I guessed my problem came from the difference in GCC versions, sadly TDM-GCC-471 doesn't seem to support std::thread...
The same code, compiled by Xcode on OSX and SFML 2.1 doesn't produce any bug.
Can you confirm the problem is indeed coming from the difference in gcc versions ?
Do you think / know that recompiling SFML with gcc 481 will solve this ?
Thanks
#include <SFML/Graphics.hpp>
#include <thread>
#include <iostream>
int main()
{
std::thread t = std::thread([](){
std::cout << "test\n";
});
if(t.joinable())
t.join();
// Create the main window
sf::RenderWindow app(sf::VideoMode(800, 600), "SFML window");
sf::Texture texture;
if (!texture.loadFromFile("cb.bmp"))
return EXIT_FAILURE;
sf::Sprite sprite(texture);
while (app.isOpen())
{
sf::Event event;
while (app.pollEvent(event))
{
if (event.type == sf::Event::Closed)
app.close();
}
app.clear();
app.draw(sprite);
app.display();
}
return EXIT_SUCCESS;
}