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

Author Topic: [SOLVED] weird crash in sf::thread  (Read 1915 times)

0 Members and 1 Guest are viewing this topic.

Gadam

  • Newbie
  • *
  • Posts: 4
  • Content
    • View Profile
    • Portfolio
    • Email
[SOLVED] weird crash in sf::thread
« on: October 03, 2016, 07:07:27 pm »
Hi,

While switching from SFML 2.3.2 to 2.4.0 on a big project, I run in a rather weird crash...

Here is a simple version :
class Base
{
public :
    virtual void foo(){};
};

class Deriv
    : public Base
{
public :
    virtual void foo(){
        printf( "hello\n" );
        sf::Font zFont;
        zFont.loadFromFile( "depend/calibri.ttf" ); //ok!
        sf::Text zText( "yolo", zFont );
        zText.getGlobalBounds();    //crash
    }
};

int main()
{
    Deriv instance;

    sf::Thread thread( &Deriv::foo, &instance );
    thread.launch();

}

1. In this example, the program crash as sool as getGlobalBounds is called.
(More precisely, it only works fine if we remove this call - my debugger is lost and cannot help more)

2. When creating the thread, if we give Base::foo instead of Deriv::foo (which should be the same), I get an error on the SFML code.
error: must use '.*' or '->*' to call pointer-to-member function ...

Note : everything was fine on SFML 2.3.2

I use Code::Blocks with mingw32-gcc-4.9.2

Have you a clue where it can come from ?
Can it be because of a bad library/compiler configuration ?
« Last Edit: October 04, 2016, 10:32:25 am by Gadam »

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: weird crash in sf::thread
« Reply #1 on: October 03, 2016, 09:44:17 pm »
Try adding a thread.join() before the main function return ; if you are using c++11 is best to use the <thread> header and use .join()/detach().


This post (answer) is a good reading about threads and resources.


Issue number 2 is resolved with
sf::Thread thread( &Base::foo, static_cast< Base* >(&instance) );
 
« Last Edit: October 03, 2016, 09:57:55 pm by DarkRoku »
I would like a spanish/latin community...
Problems building for Android? Look here

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: weird crash in sf::thread
« Reply #2 on: October 03, 2016, 10:03:40 pm »
This has less to do with the threading itself than it has to do with the stack overflow caused by #989. We are aware of this, and a fix has already been submitted for review and testing. It won't be long until this issue is fixed in the 2.4.1 release. ;)

In the mean time, you can build the current feature/no_internal_context branch and work with that.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Gadam

  • Newbie
  • *
  • Posts: 4
  • Content
    • View Profile
    • Portfolio
    • Email
Re: weird crash in sf::thread
« Reply #3 on: October 04, 2016, 10:19:33 am »
@DarkRoku : static_cast solves it indeed
@binary1248 : Looking forward for it

Thanks for your help :)
And good work guys, SFML rocks

 

anything