DART  6.7.3
dart::collision::CollisionGroup::ShapeFrameObserver Class Referencefinal

This class watches when ShapeFrames get deleted so that they can be safely removes from the CollisionGroup. More...

Inheritance diagram for dart::collision::CollisionGroup::ShapeFrameObserver:
dart::common::Observer

Public Member Functions

void addShapeFrame (const dynamics::ShapeFrame *shapeFrame)
 Add a shape frame to this observer. More...
 
void removeShapeFrame (const dynamics::ShapeFrame *shapeFrame)
 Remove a shape frame from this observer. More...
 
void removeAllShapeFrames ()
 Remove all shape frames from this observer. More...
 

Public Attributes

std::unordered_set< const dynamics::ShapeFrame * > mDeletedFrames
 Whenever an observed shape frame gets deleted, its pointer will be added to this set. More...
 

Protected Member Functions

void handleDestructionNotification (const common::Subject *subject) override
 This will be called each time an observed shape frame is deleted. More...
 
void receiveDestructionNotification (const Subject *_subject)
 Called whenever a Subject is destroyed (or sends out a destruction notification). More...
 
void addSubject (const Subject *_subject)
 Add a Subject for this Observer. More...
 
void removeSubject (const Subject *_subject)
 Remove a Subject from this Observer. More...
 
void removeAllSubjects ()
 Remove all Subjects from this Observer. More...
 

Protected Attributes

std::set< const Subject * > mSubjects
 List of current Subjects for this Observer. More...
 

Private Attributes

std::unordered_map< const common::Subject *, const dynamics::ShapeFrame * > mMap
 A map from a subject pointer to its corresponding ShapeFrame pointer. More...
 

Detailed Description

This class watches when ShapeFrames get deleted so that they can be safely removes from the CollisionGroup.

We cannot have a weak_ptr to a ShapeFrame because some are managed by std::shared_ptr while others are managed by NodePtr.

If we don't carefully track when each ShapeFrame gets destructed, then we can land in a situation where a ShapeFrame gets removed from a BodyNode, deallocated, and then a new ShapeFrame is allocated in the memory address of the old one. This can lead to invalid memory accesses if we neglect to correctly clean up our references to deleted ShapeFrames.

Member Function Documentation

◆ addShapeFrame()

void dart::collision::CollisionGroup::ShapeFrameObserver::addShapeFrame ( const dynamics::ShapeFrame shapeFrame)

Add a shape frame to this observer.

◆ addSubject()

void dart::common::Observer::addSubject ( const Subject _subject)
protectedinherited

Add a Subject for this Observer.

◆ handleDestructionNotification()

void dart::collision::CollisionGroup::ShapeFrameObserver::handleDestructionNotification ( const common::Subject subject)
overrideprotectedvirtual

This will be called each time an observed shape frame is deleted.

Reimplemented from dart::common::Observer.

◆ receiveDestructionNotification()

void dart::common::Observer::receiveDestructionNotification ( const Subject _subject)
protectedinherited

Called whenever a Subject is destroyed (or sends out a destruction notification).

Override handleDestructionNotification() in order to customize your class's response to destruction notifications.

◆ removeAllShapeFrames()

void dart::collision::CollisionGroup::ShapeFrameObserver::removeAllShapeFrames ( )

Remove all shape frames from this observer.

◆ removeAllSubjects()

void dart::common::Observer::removeAllSubjects ( )
protectedinherited

Remove all Subjects from this Observer.

◆ removeShapeFrame()

void dart::collision::CollisionGroup::ShapeFrameObserver::removeShapeFrame ( const dynamics::ShapeFrame shapeFrame)

Remove a shape frame from this observer.

◆ removeSubject()

void dart::common::Observer::removeSubject ( const Subject _subject)
protectedinherited

Remove a Subject from this Observer.

Member Data Documentation

◆ mDeletedFrames

std::unordered_set<const dynamics::ShapeFrame*> dart::collision::CollisionGroup::ShapeFrameObserver::mDeletedFrames

Whenever an observed shape frame gets deleted, its pointer will be added to this set.

The next time the collision group updates, it will check this set and wipe away any references to the pointers in this set.

◆ mMap

std::unordered_map<const common::Subject*, const dynamics::ShapeFrame*> dart::collision::CollisionGroup::ShapeFrameObserver::mMap
private

A map from a subject pointer to its corresponding ShapeFrame pointer.

This needs to be stored because by the time a Subject is being destructed, it can no longer be cast back to its ShapeFrame.

◆ mSubjects

std::set<const Subject*> dart::common::Observer::mSubjects
protectedinherited

List of current Subjects for this Observer.