[osg-users] Leveraging osgViewer without rendering to window

Hark Tag harold.r.tagunicar at saic.com
Wed Apr 13 07:41:33 PDT 2011

Hi everyone,

This is my first time using the forums, and I have a question that may seem a little strange.

My app is using osgViewer, but I am trying to make it so that it does not actually render onto the screen. I still want to use the infrastructure to update in the updateTraversal(). So in a sense, I'd like to keep all the back end parts, but remove the visual front end.

So far, what I've done is create a new class that inherits from osgViewer::Viewer. I overloaded the run() and frame() functions such that they do everything that the original code does EXCEPT call the realize() and drawTraversal() functions:


//overload this function to not call realize()
int run()
    const char* str = getenv("OSG_RUN_FRAME_COUNT");
    if (str)
            int runTillFrameNumber = atoi(str);
	    while (!done() && getViewerFrameStamp()->getFrameNumber()<runTillFrameNumber)
            while (!done())

	return 0;

    //overload this function to not include the draw
    void frame(double simulationTime)

        if (_done) return;
	if (_firstFrame)
	    _firstFrame = false;

When I do this, the application "exits normally" when it reaches the updateTraversal() method. More specifically, it exits on the line:


of that method with the following warning:

> Warning: deleting still referenced object 0x827a760 of type 'PN3osg10ReferencedE'
>          the final reference count was 1, memory corruption possible.

I definitely want to keep that functionality there so that the infrastructure is maintained. I am also confused as to why it is exiting as opposed to seg faulting. 

One of my colleagues suspects that the problem could involve the GraphicsContexts. He suggested I try creating a null GraphicsContexts that inherits from GraphicsContexts (which essentially does nothing), but I'm wondering if there is a far better option than this. 

Any insight on this would be appreciated! Thank you!


Read this topic online here:

More information about the osg-users mailing list