Canvas: Do not hold a reference to the GUI camera
It might be not be valid anymore after a reset. Just query it when needed.
This commit is contained in:
parent
f1a44c98df
commit
08aed1ccc8
2 changed files with 14 additions and 23 deletions
|
@ -97,24 +97,18 @@ CanvasMgr::CanvasMgr():
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void CanvasMgr::init()
|
void CanvasMgr::init()
|
||||||
{
|
{
|
||||||
flightgear::CameraGroup* camera_group = flightgear::CameraGroup::getDefault();
|
// add our two placement factories
|
||||||
if (camera_group) {
|
sc::Canvas::addPlacementFactory
|
||||||
_gui_camera = flightgear::getGUICamera(camera_group);
|
(
|
||||||
if (_gui_camera.valid()) {
|
"object", [](SGPropertyNode* placement, sc::CanvasPtr canvas) {
|
||||||
// add our two placement factories
|
return FGODGauge::set_aircraft_texture(placement,
|
||||||
sc::Canvas::addPlacementFactory
|
canvas->getTexture(),
|
||||||
(
|
canvas->getCullCallback(),
|
||||||
"object", [](SGPropertyNode* placement, sc::CanvasPtr canvas) {
|
canvas);
|
||||||
return FGODGauge::set_aircraft_texture(placement,
|
});
|
||||||
canvas->getTexture(),
|
sc::Canvas::addPlacementFactory("scenery-object", &addSceneObjectPlacement);
|
||||||
canvas->getCullCallback(),
|
sc::Canvas::addPlacementFactory("dynamic-model", &addDynamicModelPlacement);
|
||||||
canvas);
|
|
||||||
});
|
|
||||||
|
|
||||||
sc::Canvas::addPlacementFactory("scenery-object", &addSceneObjectPlacement);
|
|
||||||
sc::Canvas::addPlacementFactory("dynamic-model", &addDynamicModelPlacement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
simgear::canvas::CanvasMgr::init();
|
simgear::canvas::CanvasMgr::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,8 +120,6 @@ void CanvasMgr::shutdown()
|
||||||
sc::Canvas::removePlacementFactory("object");
|
sc::Canvas::removePlacementFactory("object");
|
||||||
sc::Canvas::removePlacementFactory("scenery-object");
|
sc::Canvas::removePlacementFactory("scenery-object");
|
||||||
sc::Canvas::removePlacementFactory("dynamic-model");
|
sc::Canvas::removePlacementFactory("dynamic-model");
|
||||||
|
|
||||||
_gui_camera = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
@ -147,8 +139,8 @@ CanvasMgr::getCanvasTexId(const simgear::canvas::CanvasPtr& canvas) const
|
||||||
// if( contexts.empty() )
|
// if( contexts.empty() )
|
||||||
// return 0;
|
// return 0;
|
||||||
|
|
||||||
osg::ref_ptr<osg::Camera> guiCamera;
|
osg::Camera* guiCamera = flightgear::getGUICamera(flightgear::CameraGroup::getDefault());
|
||||||
if( !_gui_camera.lock(guiCamera) )
|
if (!guiCamera)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
osg::State* state = guiCamera->getGraphicsContext()->getState(); //contexts[0]->getState();
|
osg::State* state = guiCamera->getGraphicsContext()->getState(); //contexts[0]->getState();
|
||||||
|
|
|
@ -47,7 +47,6 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
osg::observer_ptr<osg::Camera> _gui_camera;
|
|
||||||
SGPropertyChangeCallback<CanvasMgr> _cb_model_reinit;
|
SGPropertyChangeCallback<CanvasMgr> _cb_model_reinit;
|
||||||
|
|
||||||
void handleModelReinit(SGPropertyNode*);
|
void handleModelReinit(SGPropertyNode*);
|
||||||
|
|
Loading…
Reference in a new issue