1
0
Fork 0

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:
Fernando García Liñán 2021-08-31 18:14:12 +02:00
parent f1a44c98df
commit 08aed1ccc8
2 changed files with 14 additions and 23 deletions

View file

@ -97,24 +97,18 @@ CanvasMgr::CanvasMgr():
//----------------------------------------------------------------------------
void CanvasMgr::init()
{
flightgear::CameraGroup* camera_group = flightgear::CameraGroup::getDefault();
if (camera_group) {
_gui_camera = flightgear::getGUICamera(camera_group);
if (_gui_camera.valid()) {
// add our two placement factories
sc::Canvas::addPlacementFactory
(
"object", [](SGPropertyNode* placement, sc::CanvasPtr canvas) {
return FGODGauge::set_aircraft_texture(placement,
canvas->getTexture(),
canvas->getCullCallback(),
canvas);
});
sc::Canvas::addPlacementFactory("scenery-object", &addSceneObjectPlacement);
sc::Canvas::addPlacementFactory("dynamic-model", &addDynamicModelPlacement);
}
}
// add our two placement factories
sc::Canvas::addPlacementFactory
(
"object", [](SGPropertyNode* placement, sc::CanvasPtr canvas) {
return FGODGauge::set_aircraft_texture(placement,
canvas->getTexture(),
canvas->getCullCallback(),
canvas);
});
sc::Canvas::addPlacementFactory("scenery-object", &addSceneObjectPlacement);
sc::Canvas::addPlacementFactory("dynamic-model", &addDynamicModelPlacement);
simgear::canvas::CanvasMgr::init();
}
@ -126,8 +120,6 @@ void CanvasMgr::shutdown()
sc::Canvas::removePlacementFactory("object");
sc::Canvas::removePlacementFactory("scenery-object");
sc::Canvas::removePlacementFactory("dynamic-model");
_gui_camera = 0;
}
//------------------------------------------------------------------------------
@ -147,8 +139,8 @@ CanvasMgr::getCanvasTexId(const simgear::canvas::CanvasPtr& canvas) const
// if( contexts.empty() )
// return 0;
osg::ref_ptr<osg::Camera> guiCamera;
if( !_gui_camera.lock(guiCamera) )
osg::Camera* guiCamera = flightgear::getGUICamera(flightgear::CameraGroup::getDefault());
if (!guiCamera)
return 0;
osg::State* state = guiCamera->getGraphicsContext()->getState(); //contexts[0]->getState();

View file

@ -47,7 +47,6 @@ public:
protected:
osg::observer_ptr<osg::Camera> _gui_camera;
SGPropertyChangeCallback<CanvasMgr> _cb_model_reinit;
void handleModelReinit(SGPropertyNode*);