> Have you looked at a stack trace of the crash, does it involve the
> shadow code?
The stack trace seems not to be very usefull because the crash happens not
directly in the shadows code.
> Do you only see the crash if you add the shadow stuff, or more precisely
> what makes you think the shadows are the cause?
Before including the shadows, everything works fine :-). However, I attached a
minimum example based on the multithreading tutorial. If you undefine the
SHADOWS in line 27, you can see that everything runs, but with the shadows
enabled, I get a crash when
osg::Thread::getCurrent()->getChangeList()->applyTo(1); in line 163 is called.
Best regards,
Rene
--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
// all needed include files
#include <OpenSG/OSGGLUT.h>
#include <OpenSG/OSGConfig.h>
#include <OpenSG/OSGSimpleGeometry.h>
#include <OpenSG/OSGGLUTWindow.h>
#include <OpenSG/OSGSimpleSceneManager.h>
#include <OpenSG/OSGShadowViewport.h>
#include <OpenSG/OSGDirectionalLight.h>
#include <OpenSG/OSGSolidBackground.h>
#include <OpenSG/OSGThreadManager.h>
OSG_USING_NAMESPACE
using namespace std;
SimpleSceneManager *mgr;
NodePtr root;
//we will store the transformation globally - this
//is not necessary, but comfortable
TransformPtr trans;
Thread* animationThread;
Barrier *syncBarrier;
ShadowViewportPtr svp;
GLUTWindowPtr pwin;
#define SHADOWS
int setupGLUT( int *argc, char *argv[] );
NodePtr createScenegraph(){
// the scene must be created here
NodePtr n = makeTorus(.5,2,16,16);
//add a simple Transformation
trans = Transform::create();
beginEditCP(trans);
Matrix m;
m.setIdentity();
trans->setMatrix(m);
endEditCP(trans);
NodePtr transNode = Node::create();
beginEditCP(transNode);
transNode->setCore(trans);
transNode->addChild(n);
endEditCP(transNode);
return transNode;
}
//this function will run in a thread and simply will
//rotate the cube by setting a new transformation matrix
void rotate(void *args){
// we won't stop calculating new matrices....
while(true){
Real32 time = glutGet(GLUT_ELAPSED_TIME);
Matrix m;
m.setIdentity();
m.setRotate(Quaternion(Vec3f(0,1,0), time/1000));
beginEditCP(trans);
trans->setMatrix(m);
endEditCP(trans);
// nothing unusual until here
//well that's new...
//wait until two threads are cought in the
//same barrier
syncBarrier->enter(2);
//just the same again
syncBarrier->enter(2);
}
}
int main(int argc, char **argv)
{
#if OSG_MINOR_VERSION > 2
ChangeList::setReadWriteDefault();
#endif
osgInit(argc,argv);
root = createScenegraph();
//create the barrier, that will be used to
//synchronize threads
//instead of NULL you could provide a name
syncBarrier = Barrier::get(NULL);
#ifdef SHADOWS
// Create the shadowmap viewport and set initial values
// create lights
DirectionalLightPtr _point1_core;
TransformPtr point1_trans;
NodePtr point1 = makeCoredNode<DirectionalLight>(&_point1_core);
NodePtr point1_beacon = makeCoredNode<Transform>(&point1_trans);
beginEditCP(point1_trans);
point1_trans->getMatrix().setTranslate(0.0, 0.0, 0.0);
endEditCP(point1_trans);
beginEditCP(_point1_core);
_point1_core->setAmbient(0.15,0.15,0.15,1);
_point1_core->setDiffuse(1,1,1,1);
_point1_core->setSpecular(0.9,0.9,0.9,1);
_point1_core->setBeacon(point1_beacon);
_point1_core->setOn(true);
endEditCP(_point1_core);
beginEditCP(root);
root->addChild(point1);
endEditCP(root);
svp = ShadowViewport::create();
beginEditCP(svp);
svp->setBackground(SolidBackground::create());
svp->setRoot(root);
svp->setSize(0, 0, 1, 1);
svp->setMapSize(1024);
svp->setShadowMode(ShadowViewport::PCF_SHADOW_MAP);
svp->setShadowSmoothness(0.5);
// add light sources here
svp->getLightNodes().push_back(point1);
endEditCP(svp);
mgr = new osg::SimpleSceneManager;
int winid = setupGLUT(&argc, argv);
pwin = osg::GLUTWindow::create();
beginEditCP(pwin);//Window
pwin->setId(winid);
pwin->addPort(svp);
pwin->init();
endEditCP(pwin);
beginEditCP(svp);//Viewport
svp->setCamera(mgr->getCamera());
endEditCP(svp);
#else
mgr = new osg::SimpleSceneManager;
int winid = setupGLUT(&argc, argv);
pwin = osg::GLUTWindow::create();
pwin->setId(winid);
pwin->init();
#endif
mgr->setWindow( pwin );
mgr->setRoot(root);
mgr->showAll();
//create the thread that will run generation of new matrices
animationThread = dynamic_cast<Thread
*>(ThreadManager::the()->getThread("anim"));
//do it...
animationThread->runFunction(rotate, 1, NULL);
osg::Thread::getCurrent()->getChangeList()->applyTo(1);
glutMainLoop();
return 0;
}
void reshape(int w, int h)
{
mgr->resize(w, h);
glutPostRedisplay();
}
void display(void)
{
// we wait here until the animation thread enters
//the first barrier
syncBarrier->enter(2);
//now we sync data
animationThread->getChangeList()->applyAndClear();
// and again
syncBarrier->enter(2);
// !!!! Attention
// you will find a more detailed description
// of what's going on here in the documentation
// itself!
// now render...
mgr->redraw();
}
void mouse(int button, int state, int x, int y)
{
if (state)
mgr->mouseButtonRelease(button, x, y);
else
mgr->mouseButtonPress(button, x, y);
glutPostRedisplay();
}
void motion(int x, int y)
{
mgr->mouseMove(x, y);
glutPostRedisplay();
}
int setupGLUT(int *argc, char *argv[])
{
glutInit(argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
int winid = glutCreateWindow("OpenSG First Application");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutReshapeFunc(reshape);
glutIdleFunc(display);
return winid;
}
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users