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

Author Topic: Thread for class function w/ parameter  (Read 296 times)

0 Members and 1 Guest are viewing this topic.


  • Newbie
  • *
  • Posts: 4
    • View Profile
Thread for class function w/ parameter
« on: January 22, 2020, 07:29:29 pm »
Hi everybody,

I'm new on SFML and i have a problem that i understand, but can't find the right solution.

I have a class, named "Animation", with the function Play(), which take a RenderWindow parameter. I wanted to run this function in a thread, to render my animation in the same time the game is running. There is the part of the code:


        Animation(animName index) : animThread(&Animation::Play, this){
                this->Name = index;
                switch (Name) { . . . }

        ~Animation() { . . . }

        void Play(sf::RenderWindow &window);

        sf::Thread animThread;

I call it in the main() with the following code:
auto shotAnim = new Animation(animName::Shot);

And it gives me the following error: C2064: term does not evaluate to a function taking 1 arguments.

I totally understand that i don't give the necessary renderWindow parameter in "shotAnim->animThread.launch();", but i don't find where/how to set it up.

Working on Visual Studio 2017 (Debug, x86).

Can you help me please? Thanks !
« Last Edit: January 22, 2020, 08:32:33 pm by Djushima »


  • SFML Team
  • Hero Member
  • *****
  • Posts: 9670
    • View Profile
    • development blog
    • Email
Re: Thread for class function w/ parameter
« Reply #1 on: January 23, 2020, 09:35:17 am »
You really shouldn't use thread here. OpenGL is not multi-thread capable, doing multi-threading is quite complex with lots of places for failures, just have a simple update & draw/render function is a lot easier to write and understand.
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/