Added ClearModes() method to trackball to avoid leaking and corruptions due to double deletion of modes.

This commit is contained in:
Paolo Cignoni 2009-04-01 14:53:20 +00:00
parent b22077f200
commit 0c5aefb278
3 changed files with 16 additions and 11 deletions

View File

@ -264,13 +264,7 @@ void ActiveCoordinateFrame::Update()
y_axis=r.Rotate(Point3f(0,1,0));
z_axis=r.Rotate(Point3f(0,0,1));
std::map<int, TrackMode *>::iterator it;
for(it = manipulator->modes.begin(); it != manipulator->modes.end(); it++)
{
if ((*it).second)
delete (*it).second;
}
manipulator->modes.clear();
manipulator->ClearModes();
manipulator->modes[0] = NULL;
manipulator->modes[movx] = new AxisMode(p,x_axis);
manipulator->modes[movy] = new AxisMode(p,y_axis);

View File

@ -131,6 +131,12 @@ Trackball::Trackball(): current_button(0), current_mode(NULL), inactive_mode(NUL
}
Trackball::~Trackball()
{
ClearModes();
delete inactive_mode;
}
void Trackball::ClearModes()
{
// Note: people ofter maps different keys to the same modes.
// so we should avoid double deletion of these double referenced modes.
@ -140,17 +146,17 @@ Trackball::~Trackball()
if ((*it).second) goodModes.insert( (*it).second);
std::set<TrackMode *>::iterator its;
for(its = goodModes.begin(); its != goodModes.end(); its++)
for(its = goodModes.begin(); its != goodModes.end(); its++)
delete *its;
delete inactive_mode;
modes.clear();
}
void Trackball::setDefaultMapping () {
idle_and_keys_mode = NULL;
inactive_mode = new InactiveMode ();
modes.clear ();
ClearModes();
modes[0] = NULL;
modes[BUTTON_MIDDLE | KEY_ALT] =

View File

@ -285,6 +285,11 @@ public:
*/
void Reset();
/*!
@brief clear the modes map. Taking the right care of not doubledeleting anything.
*/
void ClearModes();
// DrawCircle (), DrawPlane(), DrawPlaneHandle() has been moved to trackutils.h
// the drawing code has been moved to the trackmodes
// void DrawCircle ();