diff --git a/src/Canvas/canvas_mgr.cxx b/src/Canvas/canvas_mgr.cxx index 113da4f0c..6bef1f476 100644 --- a/src/Canvas/canvas_mgr.cxx +++ b/src/Canvas/canvas_mgr.cxx @@ -75,6 +75,9 @@ CanvasMgr::CanvasMgr(): //---------------------------------------------------------------------------- void CanvasMgr::init() { + _gui_camera = flightgear::getGUICamera(flightgear::CameraGroup::getDefault()); + assert(_gui_camera.valid()); + sc::Canvas::addPlacementFactory ( "object", @@ -99,12 +102,17 @@ void CanvasMgr::shutdown() sc::Canvas::removePlacementFactory("object"); sc::Canvas::removePlacementFactory("scenery-object"); + + _gui_camera = 0; } //------------------------------------------------------------------------------ unsigned int CanvasMgr::getCanvasTexId(const simgear::canvas::CanvasPtr& canvas) const { + if( !canvas ) + return 0; + osg::Texture2D* tex = canvas->getTexture(); if( !tex ) return 0; @@ -115,8 +123,9 @@ CanvasMgr::getCanvasTexId(const simgear::canvas::CanvasPtr& canvas) const // if( contexts.empty() ) // return 0; - static osg::Camera* guiCamera = - flightgear::getGUICamera(flightgear::CameraGroup::getDefault()); + osg::ref_ptr guiCamera; + if( !_gui_camera.lock(guiCamera) ) + return 0; osg::State* state = guiCamera->getGraphicsContext()->getState(); //contexts[0]->getState(); if( !state ) diff --git a/src/Canvas/canvas_mgr.hxx b/src/Canvas/canvas_mgr.hxx index 4bc712bd9..b14403491 100644 --- a/src/Canvas/canvas_mgr.hxx +++ b/src/Canvas/canvas_mgr.hxx @@ -44,6 +44,7 @@ class CanvasMgr: protected: + osg::observer_ptr _gui_camera; SGPropertyChangeCallback _cb_model_reinit; void handleModelReinit(SGPropertyNode*);