Hi Carsten!
The modified tutorial file i made is at the bottom of this mail.
I'm using the cvs version from sourceforge of OpenSG.
Still getting the error:
WARNING: recurse: core is Null, don't know what to do!
This occurs when Im trying to change the scene.
About the other problem with barrier syncing between threads/objects; i
managed to half-way solve it. It doesn't crash anymore :)
I modified the callSync method to the following:
void OpenSGClient::callSync(){
std::cout << "callSync called\n";
syncBarrier::get(NULL); // added this line
needSync = true;
syncBarrier->enter(2);
syncBarrier->enter(2);
}
I'm not sure why i have to reinitialize the syncbarrier, it's allready
been initialized in the constructor.
But I'm now facing another problem now. When the display function runs
the command: clientHandle->getChangeList()->applyAndClear(); nothing
happens. As if doesn't recognize any change.
In my clientHandleThread looks like this:
void createOpenSGHandle(void *ptr){
std::cout << "Client handle created\n";
// init openSG thread handling - to allow external interaction
osg::ExternalThread::get(0)->initialize(0);
sleep(5);
////////////// add a box to the scene
NodePtr apa = makeBox(2,3,4,1,1,1);
NodePtr scene = client->getRoot();
beginEditCP(scene);
scene->addChild(apa);
endEditCP(scene);
sleep(1);
client->callSync(); // this is what initiate the update
while(true){
sleep(3);
std::cout << "client lives\n";
}
}
Any ides what went wrong?
Many thanks!
// Martin
/////// 00hello.cpp
#include <OpenSG/OSGThreadManager.h>
#include <OpenSG/OSGGLUT.h>
#include <OpenSG/OSGConfig.h>
#include <OpenSG/OSGSimpleGeometry.h>
#include <OpenSG/OSGGLUTWindow.h>
#include <OpenSG/OSGSimpleSceneManager.h>
OSG_USING_NAMESPACE
using namespace std;
SimpleSceneManager *mgr;
int setupGLUT( int *argc, char *argv[] );
static NodePtr scene = NullFC;
void foo(void *ptr);
Barrier *syncBarrier;
bool needSync = false;
Thread* thread;
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
ChangeList::setReadWriteDefault();
osgInit(argc,argv);
syncBarrier=Barrier::get(NULL);
// GLUT init
int winid = setupGLUT(&argc, argv);
GLUTWindowPtr gwin= GLUTWindow::create();
gwin->setId(winid);
gwin->init();
// create the scene
scene = makeTorus(.5,2,16,16);
// create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// tell the manager what to manage
mgr->setWindow(gwin );
mgr->setRoot (scene);
mgr->showAll();
thread = dynamic_cast<Thread
*>(ThreadManager::the()->getThread("Two"));
thread->runFunction(foo, 1, NULL);
// GLUT main loop
glutMainLoop();
return 0;
}
void foo(void *ptr){
sleep(3);
std::cout << "Creating object\n";
NodePtr apa = makeBox(1,2,5,1,2,3);
beginEditCP(scene);
scene->addChild(apa);
endEditCP(scene);
std::cout << "Call for sync\n";
// tells the display function that a barrier call will be made
// soon
needSync = true;
syncBarrier->enter(2);
syncBarrier->enter(2);
}
//
// GLUT callback functions
//
// redraw the window
void display(void)
{
if (needSync==true) {
needSync=false;
syncBarrier->enter(2);
thread->getChangeList()->applyAndClear();
syncBarrier->enter(2);
}
mgr->redraw();
}
// react to size changes
void reshape(int w, int h)
{
mgr->resize(w, h);
glutPostRedisplay();
}
// react to mouse button presses
void mouse(int button, int state, int x, int y)
{
if (state)
mgr->mouseButtonRelease(button, x, y);
else
mgr->mouseButtonPress(button, x, y);
glutPostRedisplay();
}
// react to mouse motions with pressed buttons
void motion(int x, int y)
{
mgr->mouseMove(x, y);
glutPostRedisplay();
}
// react to keys
void keyboard(unsigned char k, int x, int y)
{
switch(k)
{
case 27:
{
OSG::osgExit();
exit(0);
}
break;
}
}
// setup the GLUT library which handles the windows for us
int setupGLUT(int *argc, char *argv[])
{
glutInit(argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
int winid = glutCreateWindow("OpenSG");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);
glutIdleFunc(display);
return winid;
}
////// end of 00hello.cpp
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users