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

Author Topic: sf::Thread error  (Read 842 times)

0 Members and 1 Guest are viewing this topic.

Ragbot

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • Email
sf::Thread error
« on: May 04, 2021, 02:09:32 pm »
I added a new thread to my code and I keep getting this error...

D:\tmp\source\cp\audio_GUI\src\Mp3.cpp:214:12: warning: deleting 'void*' is undefined [-Wdelete-incomplete]
  214 |     delete rawMp3Data;
      |            ^~~~~~~~~~
In file included from D:\tmp\source\cp\audio_GUI\include/SFML/System/Thread.hpp:193,
                 from D:\tmp\source\cp\audio_GUI\include/SFML/System.hpp:43,
                 from D:\tmp\source\cp\audio_GUI\include/SFML/Window.hpp:32,
                 from D:\tmp\source\cp\audio_GUI\include/App/window.hpp:4,
                 from D:\tmp\source\cp\audio_GUI\src\window.cpp:1:
D:\tmp\source\cp\audio_GUI\include/SFML/System/Thread.inl: In instantiation of 'void sf::priv::ThreadFunctor<T>::run() [with T = void (au::Window::*)()]':
D:\tmp\source\cp\audio_GUI\include/SFML/System/Thread.inl:39:18:   required from here
D:\tmp\source\cp\audio_GUI\include/SFML/System/Thread.inl:39:34: error: must use '.*' or '->*' to call pointer-to-member function in '((sf::priv::ThreadFunctor<void (au::Window::*)()>*)this)->sf::priv::ThreadFunctor<void (au::Window::*)()>::m_functor (...)', e.g. '(... ->* ((sf::priv::ThreadFunctor<void (au::Window::*)()>*)this)->sf::priv::ThreadFunctor<void (au::Window::*)()>::m_functor) (...)'
   39 |     virtual void run() {m_functor();}
      |                         ~~~~~~~~~^~

Build finished with error(s).
The terminal process terminated with exit code: -1.
 

This is my code :

void au::Window::loop()
{
    sf::Thread thread_new(&mouse_pos_loop);
    thread_new.launch();

    while(r_window.isOpen())
    {
        render();
        event_handler();
       
    }
}
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9818
    • View Profile
    • development blog
    • Email
Re: sf::Thread error
« Reply #1 on: May 04, 2021, 02:58:45 pm »
The error is quite precise.

rawMp3Data is seen as a void pointer, which you can delete, since type and thus memory size information is missing.

Why this is happening with a thread, I don't know, especially since I don't know what mouse_pos_loop does.

Personally recommendation: Don't use threads, unless you're an expert on the topic. There are a lot of complexities and issue that threads can introduce and more often than not, it doesn't actually solve the thing you imagined it would solve.
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/

Ragbot

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • Email
Re: sf::Thread error
« Reply #2 on: May 04, 2021, 04:23:53 pm »
rawMp3Data is from a different class and has no relation to this code here but I will fix that,

and mouse_pos_loop() is an empty function I was trying to get a live feed of my mouse position in my so is it possible without sf::Thread? 

kojack

  • Newbie
  • *
  • Posts: 47
    • View Profile
Re: sf::Thread error
« Reply #3 on: May 04, 2021, 04:38:16 pm »
It seems to dislike the type of mouse_pos_loop.
How exactly is mouse_pos_loop declared? Also what exactly are au and Window? Namespaces or classes?
For example a free function in a namespace is different to a member function in a class when it comes to binding them to things like threads.

Ragbot

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • Email
Re: sf::Thread error
« Reply #4 on: May 05, 2021, 07:50:21 am »

au is namespace which contains the class Window

void au::Window::loop()
{
    sf::Thread thread_new(&mouse_pos_loop);
    thread_new.launch();

    while(r_window.isOpen())
    {
        render();
        event_handler();        
    }
}

// Misc //

void au::Window::mouse_pos_loop()
{ r_mouse_pos = sf::Mouse::getPosition(); }
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9818
    • View Profile
    • development blog
    • Email
Re: sf::Thread error
« Reply #5 on: May 05, 2021, 08:29:00 am »
See the example 2 in the documentation on how to pass a member function of a class.

and mouse_pos_loop() is an empty function I was trying to get a live feed of my mouse position in my so is it possible without sf::Thread? 
You're updating your window at 60+fps anyways, that's more than enough for a "live feed", you don't need to spin on another thread.
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/

Ragbot

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • Email
Re: sf::Thread error
« Reply #6 on: May 05, 2021, 03:13:42 pm »
Oh ok thx