From: durk Date: Sat, 19 Apr 2008 10:28:07 +0000 (+0000) Subject: Torsten Dreyer: Check whether a valid graphic context has been created X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8055c315ac9d63203110b14fd1fe7afa09d1f0bc;p=flightgear.git Torsten Dreyer: Check whether a valid graphic context has been created before using a camera. --- diff --git a/src/Main/fg_os_osgviewer.cxx b/src/Main/fg_os_osgviewer.cxx index a713e0627..c652dc3cd 100644 --- a/src/Main/fg_os_osgviewer.cxx +++ b/src/Main/fg_os_osgviewer.cxx @@ -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 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);