Hello Conan,

I create my gc manually then create viewer/window etc... so my code looks like 
this:

unsigned int contextID = gc.get()->getState()->getContextID()
unsigned int textureID = texture[0]->getTextureObject(contextID)->id();

Upon executing the "textureID = " I get a seg fault, and upon further checking,  
texture[0]->getTextureObject(contextID) = 0.

(you don't need gc.get() above, ref_ptr has an overloaded operator-> that takes care of that for you so you can just do gc->... )

As with any pointer access in C++ programming, you have to be sure that when you do something, you're not dereferencing a null pointer.

What you're doing is perfectly fine, as long as you do it after the first frame has rendered. The getTextureObject(...) call will return NULL before that, because OSG uses lazy initialization to only allocate objects once they're needed. OpenGL objects and the OSG objects that hold them are examples of this.

So the safest way is to just let OSG render one frame, and then you can get your texture object (for example, check if the result of getTextureObject() is NULL, if not then get your texture ID, and then do your thing).

If you really want to, you can force OSG to allocate all objects in your scene at startup by doing this:

        viewer->realize();
        viewer->stopThreading();

        gc->makeCurrent();

        osgUtil::GLObjectsVisitor glov;
        glov.setState(gc->getState());
        viewer->getCamera()->accept(glov);

        gc->releaseContext();

        viewer->startThreading();

Hope this helps,

J-S
--
______________________________________________________
Jean-Sebastien Guay    jean-sebastien.g...@cm-labs.com
                               http://www.cm-labs.com/
                    http://whitestar02.dyndns-web.com/
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to