1
0
Fork 0

Fix clean up of the PUI event handler on reset

This commit is contained in:
James Turner 2020-08-11 18:33:05 +01:00
parent c913b752fc
commit 56089b9dd9
2 changed files with 19 additions and 1 deletions

View file

@ -43,6 +43,7 @@
#include <Main/locale.hxx>
#include <Viewer/CameraGroup.hxx>
#include <Viewer/FGEventHandler.hxx>
#include <Viewer/renderer.hxx>
#include <Input/input.hxx>
#include <Input/FGMouseInput.hxx>
@ -270,6 +271,16 @@ PUICamera::PUICamera() :
{
}
PUICamera::~PUICamera()
{
SG_LOG(SG_GL, SG_INFO, "Deleting PUI camera");
auto viewer = globals->get_renderer()->getViewer();
if (viewer) {
viewer->removeEventHandler(_eventHandler);
}
}
void PUICamera::init(osg::Group* parent, osgViewer::Viewer* viewer)
{
setName("PUI FBO camera");
@ -339,7 +350,8 @@ void PUICamera::init(osg::Group* parent, osgViewer::Viewer* viewer)
// push_front so we keep the order of event handlers the opposite of
// the rendering order (i.e top-most UI layer has the front-most event
// handler)
viewer->getEventHandlers().push_front(new PUIEventHandler(this));
_eventHandler = new PUIEventHandler(this);
viewer->getEventHandlers().push_front(_eventHandler);
}
// remove once we require OSG 3.4

View file

@ -30,6 +30,10 @@ namespace osgViewer {
class Viewer;
}
namespace osgGA {
class GUIEventHandler;
}
namespace flightgear
{
@ -39,6 +43,7 @@ public:
static void initPUI();
PUICamera();
virtual ~PUICamera();
osg::Object* cloneType() const override { return new PUICamera; }
osg::Object* clone(const osg::CopyOp&) const override { return new PUICamera; }
@ -53,6 +58,7 @@ private:
osg::Texture2D* _fboTexture = nullptr;
osg::Geometry* _fullScreenQuad = nullptr;
osgGA::GUIEventHandler* _eventHandler = nullptr;
static void puGetWindowSize(int *width, int *height);
static int puGetWindow();