Brian Keener wrote:
Typing esc only destroys the window without stopping the program, which
continue with a
dangling viewer pointer; no wonder that you have to kill it manually.
Instead of calling glutDestroyWindow(glutGetWindow()); it should call
exit(0); , maybe after
calling delete viewer; .
I think he's right about the exit() call. The delete viewer should
already be taken care of by the ref_ptr.
void display(void)
{
// update and render the scene graph
if (viewer.valid()) viewer->frame();
// Swap Buffers
glutSwapBuffers();
glutPostRedisplay();
}
glutPostRedisplay(); will have display() called again, so it creates an
infinite loop.
It should not be there. glutPostRedisplay(); should rather be at the end
of
mousebutton, mousemove, and keyboard.
Seems to me that the viewer->frame() call should be in a glutIdleFunc,
not a glutDisplayFunc(). From the man page:
"The amount of computation and rendering done in an idle callback should
be minimized to avoid affecting the program's interactive response. In
general, not more than a single frame of rendering should be done in an
idle callback."
So, it's acceptable to render a single frame from the idle callback.
The display callback is better used for programs that don't need drawing
to be done continuously. OSG apps don't typically fall into this category.
Closing the window with the (X) icon should result in simply calling
exit(0) and destroying the
window. As to why it segfaults, you would have to degug it, as I don't
have
OpenSceneGraph installed.
Probably the viewer isn't being cleaned up in this case, and it still
tries to draw with an invalid window or context. This is just a guess,
though.
--"J"
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org