Corrected long standing bug of double deletion of trackmodes. New safer destructor
This commit is contained in:
parent
2dfa6976ac
commit
16e51c9d75
|
@ -111,6 +111,7 @@ Adding copyright.
|
|||
|
||||
#include <GL/glew.h>
|
||||
#include "trackball.h"
|
||||
#include<set>
|
||||
|
||||
#include <wrap/gl/math.h>
|
||||
#include <wrap/gl/space.h>
|
||||
|
@ -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<TrackMode *> goodModes;
|
||||
std::map<int, TrackMode *>::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<TrackMode *>::iterator its;
|
||||
for(its = goodModes.begin(); its != goodModes.end(); its++)
|
||||
delete *its;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -199,6 +199,11 @@ public:
|
|||
@warning The destructor <b>does not</b> 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.
|
||||
|
||||
|
|
Loading…
Reference in New Issue