-
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();
}
}
-
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.
-
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?
-
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.
-
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(); }
-
See the example 2 in the documentation (https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Thread.php#details) 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.
-
Oh ok thx
-
So uh now I have another issue with sf::Thread or rather maybe its just not a feature but
when ever I pass in more than 1 variable it gives me a bunch of errors
$ g++ main.cpp `pkg-config --libs sfml-all`
main.cpp: In function 'int main()':
main.cpp:14:33: error: no matching function for call to 'sf::Thread::Thread(int (*)(const char*, const char*), const char [4], const char [4])'
14 | sf::Thread t(&foo, "str", "lol");
| ^
In file included from D:/msys64/mingw64/include/SFML/System.hpp:43,
from main.cpp:2:
D:/msys64/mingw64/include/SFML/System/Thread.hpp:126:5: note: candidate: 'template<class C> sf::Thread::Thread(void (C::*)(), C*)'
126 | Thread(void(C::*function)(), C* object);
| ^~~~~~
D:/msys64/mingw64/include/SFML/System/Thread.hpp:126:5: note: template argument deduction/substitution failed:
main.cpp:14:33: note: mismatched types 'void (C::*)()' and 'int (*)(const char*, const char*)'
14 | sf::Thread t(&foo, "str", "lol");
| ^
In file included from D:/msys64/mingw64/include/SFML/System.hpp:43,
from main.cpp:2:
D:/msys64/mingw64/include/SFML/System/Thread.hpp:103:5: note: candidate: 'template<class F, class A> sf::Thread::Thread(F, A)'
103 | Thread(F function, A argument);
| ^~~~~~
D:/msys64/mingw64/include/SFML/System/Thread.hpp:103:5: note: template argument deduction/substitution failed:
main.cpp:14:33: note: candidate expects 2 arguments, 3 provided
14 | sf::Thread t(&foo, "str", "lol");
| ^
In file included from D:/msys64/mingw64/include/SFML/System.hpp:43,
from main.cpp:2:
D:/msys64/mingw64/include/SFML/System/Thread.hpp:75:5: note: candidate: 'template<class F> sf::Thread::Thread(F)'
75 | Thread(F function);
| ^~~~~~
D:/msys64/mingw64/include/SFML/System/Thread.hpp:75:5: note: template argument deduction/substitution failed:
main.cpp:14:33: note: candidate expects 1 argument, 3 provided
14 | sf::Thread t(&foo, "str", "lol");
| ^
In file included from D:/msys64/mingw64/include/SFML/System.hpp:43,
from main.cpp:2:
D:/msys64/mingw64/include/SFML/System/Thread.hpp:48:23: note: candidate: 'sf::Thread::Thread(const sf::Thread&)'
48 | class SFML_SYSTEM_API Thread : NonCopyable
| ^~~~~~
D:/msys64/mingw64/include/SFML/System/Thread.hpp:48:23: note: candidate expects 1 argument, 3 provided
code:
#include <iostream>
#include <SFML/System.hpp>
#include <string>
int foo(const char x[], const char y[])
{
while(1)
std::cout << "Func foo(int) << param: " << x << std::endl;
}
int main()
{
sf::Thread t(&foo, "str", "lol");
t.launch();
while(1)
{
std::cout << "main thread" << std::endl;
}
return 0;
}
So is there any way to use multiple parameters?
or do I have to go with std::thread?
-
Just read the documentation - Threads (https://www.sfml-dev.org/tutorials/2.5/system-thread.php)
In your case:
sf::Thread t(std::bind(&foo, "str", "lol"));