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

Author Topic: std::thread and SFML 2.1, segmentation fault on std::thread.join()  (Read 1973 times)

0 Members and 1 Guest are viewing this topic.

Tyrendel

  • Newbie
  • *
  • Posts: 10
    • View Profile
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;
}
 
« Last Edit: July 23, 2014, 04:13:52 pm by Tyrendel »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: std::thread and SFML 2.1, segmentation fault on std::thread.join()
« Reply #1 on: July 23, 2014, 04:14:09 pm »
You should try to recompile SFML.
Laurent Gomila - SFML developer

Tyrendel

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: std::thread and SFML 2.1, segmentation fault on std::thread.join()
« Reply #2 on: July 23, 2014, 05:33:16 pm »
I recompiled SFML on my current environement and the bug is now gone.

Thanks !

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
AW: std::thread and SFML 2.1, segmentation fault on std::thread.join()
« Reply #3 on: July 23, 2014, 05:44:12 pm »
On a general note any C++ library you use needs to be compiled with the same compiler as you're building your application with.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/