N.P. :)
The problem is that runFunction expects a function returning void taking
a void ptr, (as can be seen by void (*)(void*)). The type of your
'runFunction' is actually void (TestFader::*)(void*), since it is a
member function.
I suggest you make 'runFunction' static, that should do the trick. Or,
if you want to run a member function on an object, you could do somethin
like this:
void launcher(void* p) {
reinterpret_cast<TestFader*>(p)->runFunction();
}
which, of course, could be static in TestFader as well.
Regards
/Marcus
Markus Straub wrote:
Oh, sorry for forgetting to post the error message!
I get a compiler error:
TestFader.cpp: In member function `int TestFader::startThread()':
TestFader.cpp:17: error: no matching function for call to `osg::Thread::
runFunction(<unknown type>, int, NULL)'
/usr/local/include/OpenSG/OSGThread.h:186: error: candidates are: bool
osg::PThreadBase::runFunction(void (*)(void*), unsigned int, void*)
make: *** [t] Error 1
the Makefile: (I just added all the compileflags that are used in the
OpenSG/Tutorials)
//-------------<begin Makefile>------------------
CC = g++
COMPILEFLAGS = -lopenal -D_GNU_SOURCE -DQT_CLEAN_NAMESPACE
-DOSG_WITH_GLUT -DOSG_WITH_TIF -DOSG_WITH_JPG -DOSG_WITH_PNG
-D_OSG_HAVE_CONFIGURED_H_ -DQT_NO_XINERAMA -DQT_NO_XRENDER
-DQT_NO_XFTFREETYPE -DQT_NO_XKB -DQT_NO_SM_SUPPORT -DQT_NO_IMAGEIO_MNG
-DQT_NO_IMAGEIO_JPEG -DQT_NO_STYLE_AQUA -DQT_NO_STYLE_MAC
-DQT_NO_STYLE_INTERLACE -DQT_NO_STYLE_COMPACT -ansi
-use_readonly_const -ftemplate-depth-100 -g -DOSG_DEBUG
-DOSG_WITH_GLUT -DOSG_WITH_TIF -DOSG_WITH_JPG -DOSG_WITH_PNG
-I/usr/include -I/usr/local/include -g -L/usr/lib
-L/usr/local/lib/dbg -lOSGWindowGLUT -lOSGSystem -lOSGBase -ltiff
-ljpeg -lpng -lz -lglut -lGLU -lGL -lXmu -lXi -lXt -lX11 -lpthread
-ldl -lm -L/usr/X11R6/lib
t:
$(CC) $(COMPILEFLAGS) -o t.out TestFader.cpp -Wall -pedantic
./t.out
//-------------<end Makefile>------------------
Kind regards, Markus
Marcus Lindblom wrote:
What is it that doesn't work? Compiler error? Link error? Runtime error?
Regards,
/Marcus
Markus Straub wrote:
Hi all,
I would like to know, if it is possible, to create an osg::Thread
from a c++ class-member-function. My guess is, that the osg::Thread
is not designed for that purpose, it relies on pthreads, doesn't it?
I created a simple program which uses threads in C:
//-------------<begin TestFader.c>------------------
#include <iostream.h>
#include <OpenSG/OSGGLUTWindow.h>
osg::Thread* tfadeOut;
void fadeOut(void *ptr){
cout << "it works!\n";
}
int startThread(){
// declaration & start of the thread
tfadeOut = dynamic_cast<osg::Thread
*>(osg::ThreadManager::the()->getThread("fOut"));
tfadeOut->runFunction(fadeOut, 0, NULL);
return 0;
}
int main(int argc, char **argv){
osg::osgInit(argc,argv);
startThread();
osg::Thread::join(tfadeOut);
return 0;
}
//-------------<end TestFader.c>------------------
This code works perfectly and prints out "it works". Nevertheless my
attempts to put the same code into a class won't bring any positive
results. My C++ code looks like this:
//-------------<begin TestFader.cpp>------------------
#include <iostream.h>
#include <OpenSG/OSGGLUTWindow.h>
class TestFader{
public:
osg::Thread* tfadeOut;
void fadeOut(void *ptr){
cout << "it works!\n";
}
int startThread(){
// declaration & start of the thread
tfadeOut = dynamic_cast<osg::Thread
*>(osg::ThreadManager::the()->getThread("fOut"));
tfadeOut->runFunction(TestFader::fadeOut, 0, NULL);
cout << "it works!\n";
return 0;
}
};
int main(int argc, char **argv){
TestFader *f = new TestFader();
osg::osgInit(argc,argv);
f->startThread();
osg::Thread::join(f->tfadeOut);
return 0;
}
//-------------<end TestFader.cpp>------------------
So has anybody got a hint for me on how to create threads from c++
class-member-functions with OSG-Threads? That would really be
appreciated.
Thanks, Markus
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through
log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through
log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log
files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users