From 0b6f0f1fd993a747818e2e28ecd904b09f8a81ed Mon Sep 17 00:00:00 2001 From: Daan van Hasselt Date: Fri, 7 Aug 2020 14:21:38 +0200 Subject: [PATCH] disconnect the update function on destruction --- src/Cinder-LeapMotion.cpp | 5 ++++- src/Cinder-LeapMotion.h | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Cinder-LeapMotion.cpp b/src/Cinder-LeapMotion.cpp index a373be5..84f5573 100644 --- a/src/Cinder-LeapMotion.cpp +++ b/src/Cinder-LeapMotion.cpp @@ -179,13 +179,16 @@ Device::Device() mListener.mMutex = &mMutex; mController = new Leap::Controller( mListener ); - App::get()->getSignalUpdate().connect( bind( &Device::update, this ) ); + mUpdateConnection = App::get()->getSignalUpdate().connect( bind( &Device::update, this ) ); } Device::~Device() { disconnectEventHandler(); mController->removeListener( mListener ); + if (mUpdateConnection.isConnected()) { + mUpdateConnection.disconnect(); + } } Leap::Controller* Device::getController() const diff --git a/src/Cinder-LeapMotion.h b/src/Cinder-LeapMotion.h index 2d2f6b2..22ff6a3 100644 --- a/src/Cinder-LeapMotion.h +++ b/src/Cinder-LeapMotion.h @@ -40,6 +40,7 @@ #include "cinder/Channel.h" #include "cinder/Matrix.h" #include "cinder/Vector.h" +#include "cinder/Signals.h" #include #include @@ -129,7 +130,8 @@ class Device std::function mEventHandler; - virtual void update(); + ci::signals::Connection mUpdateConnection; + virtual void update(); Leap::Controller* mController; Leap::Device mDevice;