SFML community forums

Help => General => Topic started by: Honorabl3 on September 30, 2013, 07:17:51 pm

Title: sf::Thread being used in class functions. [SFML 2.1]
Post by: Honorabl3 on September 30, 2013, 07:17:51 pm
I'm on my phone to type this, but I wanted to see if there was a solution to my problem. I won't be going into too much depth unless really absoluty needed. Anyway I'll hop into the issue.

It seems when I tell a thread to run from a class method, it won't work.
Code: [Select]
void player::blah()
{
     sf::Thread thread(&rawr, sf::Vector2f(6, 5));
     thread.launch();
}

void player::rawr(sf::Vector2f dir)
{
      //rawr stuff
}

P.S. I have read the thread documentation. It hasn't helped.
Title: Re: sf::Thread being used in class functions. [SFML 2.1]
Post by: G. on September 30, 2013, 07:39:19 pm
Seriously (http://www.sfml-dev.org/tutorials/2.1/system-thread.php#common-mistakes)?
Title: AW: sf::Thread being used in class functions. [SFML 2.1]
Post by: eXpl0it3r on September 30, 2013, 08:26:43 pm
Yep read the last paragraph "again". The thread goes out of scope, thus gets destroyed and join is called in the destructor. ;)
Title: Re: sf::Thread being used in class functions. [SFML 2.1]
Post by: Honorabl3 on September 30, 2013, 09:38:32 pm
Well, that seems to be the answer to my three day problem I've been having. Once I get home I'll test it.