From 7463ebad1d0c203fd892d7d54a57ffa41208c1df Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Sat, 1 Sep 2012 16:50:21 +0200 Subject: [PATCH] Canvas: Only use cull callback if it's still valid --- src/Canvas/canvas.cxx | 2 +- src/Canvas/canvas.hxx | 8 +++++--- src/Canvas/elements/CanvasImage.cxx | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Canvas/canvas.cxx b/src/Canvas/canvas.cxx index eca171c38..1e64f7958 100644 --- a/src/Canvas/canvas.cxx +++ b/src/Canvas/canvas.cxx @@ -73,7 +73,7 @@ Canvas::CullCallback::CullCallback(CameraCullCallback* camera_cull): void Canvas::CullCallback::operator()( osg::Node* node, osg::NodeVisitor* nv ) { - if( nv->getTraversalMask() & simgear::MODEL_BIT ) + if( (nv->getTraversalMask() & simgear::MODEL_BIT) && _camera_cull.valid() ) _camera_cull->enableRendering(); traverse(node, nv); diff --git a/src/Canvas/canvas.hxx b/src/Canvas/canvas.hxx index 29d9ee93e..dbfae12fe 100644 --- a/src/Canvas/canvas.hxx +++ b/src/Canvas/canvas.hxx @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -66,6 +67,7 @@ class Canvas: virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); }; typedef osg::ref_ptr CameraCullCallbackPtr; + typedef osg::observer_ptr CameraCullCallbackWeakPtr; /** * This callback is installed on every placement of the canvas in the @@ -78,7 +80,7 @@ class Canvas: CullCallback(CameraCullCallback* camera_cull); private: - CameraCullCallback *_camera_cull; + CameraCullCallbackWeakPtr _camera_cull; virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); }; @@ -91,10 +93,10 @@ class Canvas: int getSizeX() const { return _size_x; } - + int getSizeY() const { return _size_y; } - + void setSizeX(int sx); void setSizeY(int sy); diff --git a/src/Canvas/elements/CanvasImage.cxx b/src/Canvas/elements/CanvasImage.cxx index 77ddbce13..17dd5e0cf 100644 --- a/src/Canvas/elements/CanvasImage.cxx +++ b/src/Canvas/elements/CanvasImage.cxx @@ -43,7 +43,7 @@ class CullCallback: CullCallback(Canvas::CameraCullCallback* camera_cull); private: - Canvas::CameraCullCallback *_camera_cull; + Canvas::CameraCullCallbackWeakPtr _camera_cull; virtual bool cull( osg::NodeVisitor* nv, osg::Drawable* drawable, @@ -62,7 +62,8 @@ bool CullCallback::cull( osg::NodeVisitor* nv, osg::Drawable* drawable, osg::RenderInfo* renderInfo ) const { - _camera_cull->enableRendering(); + if( _camera_cull.valid() ) + _camera_cull->enableRendering(); // TODO check if window/image should be culled return false;