diff --git a/wrap/gui/trackball.cpp b/wrap/gui/trackball.cpp index ac57f410..5123e27a 100644 --- a/wrap/gui/trackball.cpp +++ b/wrap/gui/trackball.cpp @@ -111,6 +111,7 @@ Adding copyright. #include #include "trackball.h" +#include #include #include @@ -131,12 +132,16 @@ Trackball::Trackball(): current_button(0), current_mode(NULL), inactive_mode(NUL Trackball::~Trackball() { + // Note: people ofter maps different keys to the same modes. + // so we should avoid double deletion of these double referenced modes. + std::set goodModes; std::map::iterator it; for(it = modes.begin(); it != modes.end(); it++) - { - if ((*it).second) - delete (*it).second; - } + if ((*it).second) goodModes.insert( (*it).second); + + std::set::iterator its; + for(its = goodModes.begin(); its != goodModes.end(); its++) + delete *its; } diff --git a/wrap/gui/trackball.h b/wrap/gui/trackball.h index 7d668107..988ecf85 100644 --- a/wrap/gui/trackball.h +++ b/wrap/gui/trackball.h @@ -199,6 +199,11 @@ public: @warning The destructor does not deallocate the memory allocated by setDefaultMapping(), because the application can change the modes map. This can lead to small memory leaks, so please explicitally delete any manipulator in the modes map if you are going to repeatly allocate and deallocate Trackball instances. */ ~Trackball(); + + private: + // TriMesh cannot be copied. Use Append (see vcg/complex/trimesh/append.h) + Trackball operator =(const Trackball & m){} + public: /*! @brief Reset the trackball.