Hi Dirk,
thanks for the quick response.
On Saturday 19 November 2005 02:26, Dirk Reiners wrote:
> Hi Martin,
>
> On Fri, 2005-11-18 at 18:47 +0100, Martin Röder wrote:
> > Can I somehow force the Image object to get serialized before the Terrain
> > object, or am I wrong about the problem? Any hints on displaying a
> > Terrain object on a cluster server would be appreciated.
>
> Hm, the system should do that automatically.
>
> There might be a bug in the ImageFileHandler, though. Are you using
> ImageFileHandler::read()? If yes, could you try adding a beginEditCP
> (image); endEditCP(image); after loading the image and see if that
> helps?
Yes, I used ImageFileHandler::read, and I tried adding beginEditCP(image);
endEditCP(image);, but it does not help. I now have a very minimalistic test
program that does not use ImageFileHandler but creates an Image in memory.
The same problem shows up in this test. I attached the program. If you run it
without command line parameters, it creates a scene with a Terrain node,
writes it to the file "test.bin" and then displays the scene. If you run it
with one or more parameters, it will try to load a scene from "test.bin" and
then display the scene. However, the load does not succeed and the program
crashes in Terrain::changed (same problem as in my cluster test). However,
the test program shows some other interesting behavior. First, loading a
saved scene with a Terrain node works if the scene was saved to an OSG file
instead of a BIN file, but it seems that the OSGWriter does not use the same
serialization methods that are used by OSGRemoteAspect and BINWriter, so this
does not help. The second thing is much more interesting: If I change the
order of the scene creation commands from
TerrainPtr terrain = Terrain::create();
ImagePtr height = Image::create();
beginEditCP(height);
height->set(Image::OSG_L_PF,5,5);
height->clear(0);
height->getData()[7]=16;
endEditCP(height);
beginEditCP(terrain);
terrain->setHeightData(height);
endEditCP(terrain);
scene = Node::create();
beginEditCP(scene);
scene->setCore(terrain);
endEditCP(scene);
to
ImagePtr height = Image::create();
beginEditCP(height);
height->set(Image::OSG_L_PF,5,5);
height->clear(0);
height->getData()[7]=16;
endEditCP(height);
TerrainPtr terrain = Terrain::create();
beginEditCP(terrain);
terrain->setHeightData(height);
endEditCP(terrain);
scene = Node::create();
beginEditCP(scene);
scene->setCore(terrain);
endEditCP(scene);
i.e. the terrain object is created after the image editing is finished,
everything else is the same, then the loading of the resulting BIN file
crashes at a different location. Actually, the Image data is read before the
Terrain data in this case (as it should be), but something else goes wrong. I
get
WARNING: ERROR in BINLoader::chargeFieldContainers():
no matching container found for ID 0
THIS SHOULD NOT HAPPEN!!!
WARNING: ERROR in BINLoader::chargeFieldContainers():
no matching container found for ID 16777216
THIS SHOULD NOT HAPPEN!!!
WARNING: ERROR in BINLoader::chargeFieldContainers():
no matching container found for ID 2566914048
THIS SHOULD NOT HAPPEN!!!
WARNING: ERROR in BINLoader::chargeFieldContainers():
no matching container found for ID 419430400
THIS SHOULD NOT HAPPEN!!!
WARNING: ERROR in BINLoader::chargeFieldContainers():
no matching container found for ID 0
THIS SHOULD NOT HAPPEN!!!
and then the program crashes in
Action::ResultE SingleTypeGraphOp<Type>::traverseEnter. It looks very strange
to me that this small change in the scene creation order leads to such
different behaviors. I hope it's not just a compiler bug. By the way, I used
gcc 3.3.5 and OpenSG 1.6.0 (release version) for this test.
Regards
Martin
#include <OpenSG/OSGGLUT.h>
#include <OpenSG/OSGConfig.h>
#include <OpenSG/OSGGLUTWindow.h>
#include <OpenSG/OSGSimpleSceneManager.h>
#include <OpenSG/OSGSceneFileHandler.h>
#include <OpenSG/OSGTerrain.h>
#include <OpenSG/OSGImage.h>
// Activate the OpenSG namespace
OSG_USING_NAMESPACE
// The SimpleSceneManager to manage simple applications
SimpleSceneManager *mgr;
//
// GLUT callback functions
//
// redraw the window
void display(void)
{
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();
}
// 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);
return winid;
}
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
ChangeList::setReadWriteDefault();
osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
// Window init
GLUTWindowPtr win=GLUTWindow::create();
beginEditCP(win);
win->setId(winid);
win->setSize(300,300);
endEditCP(win);
NodePtr scene;
if(argc<=1)
{
// create the scene
TerrainPtr terrain = Terrain::create();
ImagePtr height = Image::create();
beginEditCP(height);
height->set(Image::OSG_L_PF,5,5);
height->clear(0);
height->getData()[7]=16;
endEditCP(height);
beginEditCP(terrain);
terrain->setHeightData(height);
endEditCP(terrain);
scene = Node::create();
beginEditCP(scene);
scene->setCore(terrain);
endEditCP(scene);
SceneFileHandler::the().write(scene,"test.bin");
}
else
{
// read the scene from test.bin
scene = SceneFileHandler::the().read("test.bin");
}
// create the SimpleSceneManager helper
mgr = new SimpleSceneManager;
// tell the manager what to manage
mgr->setWindow(win );
mgr->setRoot (scene);
// show the whole scene
mgr->showAll();
// initialize window
win->init();
// GLUT main loop
glutMainLoop();
return 0;
}