]> git.mxchange.org Git - flightgear.git/commitdiff
Torsten Dreyer: Check whether a valid graphic context has been created
authordurk <durk>
Sat, 19 Apr 2008 10:28:07 +0000 (10:28 +0000)
committerdurk <durk>
Sat, 19 Apr 2008 10:28:07 +0000 (10:28 +0000)
before using a camera.

src/Main/fg_os_osgviewer.cxx

index a713e0627e16fa74a2eee4b3453bc08ef8f4838f..c652dc3cdf9c3860b71025bbe1141bd35b81eb9f 100644 (file)
@@ -172,7 +172,6 @@ void fgOSOpenWindow(int w, int h, int bpp,
         if (strcmp(cameraNode->getName(), "camera") != 0)
           continue;
 
-       nCameras++;
         // get a new copy of the traits struct
         osg::ref_ptr<osg::GraphicsContext::Traits> cameraTraits;
         cameraTraits = new osg::GraphicsContext::Traits(*traits);
@@ -209,14 +208,17 @@ void fgOSOpenWindow(int w, int h, int bpp,
 
         osg::GraphicsContext* gc;
         gc = osg::GraphicsContext::createGraphicsContext(cameraTraits.get());
-        gc->realize();
-        camera->setGraphicsContext(gc);
-        // If a viewport isn't set on the camera, then it's hard to dig it
-        // out of the SceneView objects in the viewer, and the coordinates
-        // of mouse events are somewhat bizzare.
-        camera->setViewport(new osg::Viewport(0, 0, cameraTraits->width, cameraTraits->height));
-        camera->setProjectionResizePolicy(rsp);
-        viewer->addSlave(camera.get(), osg::Matrix::translate(-shearx, -sheary, 0), osg::Matrix());
+        if( gc != NULL ) {
+          gc->realize();
+          camera->setGraphicsContext(gc);
+          // If a viewport isn't set on the camera, then it's hard to dig it
+          // out of the SceneView objects in the viewer, and the coordinates
+          // of mouse events are somewhat bizzare.
+          camera->setViewport(new osg::Viewport(0, 0, cameraTraits->width, cameraTraits->height));
+          camera->setProjectionResizePolicy(rsp);
+          viewer->addSlave(camera.get(), osg::Matrix::translate(-shearx, -sheary, 0), osg::Matrix());
+          nCameras++;
+        }
       }
       if (nCameras > 1)
        manipulator->setResizable(false);