Skip to content
This repository has been archived by the owner on Jun 28, 2019. It is now read-only.

Commit

Permalink
Add some helpers to fix a mem leak :(
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 21, 2016
1 parent 42f734b commit 4199964
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
10 changes: 10 additions & 0 deletions BEPUphysics/BroadPhaseEntries/Collidable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,23 @@ protected set
shape.ShapeChanged -= shapeChangedDelegate;
shape = value;
if (shape != null)
{
shape.ShapeChanged += shapeChangedDelegate;
}
OnShapeChanged(shape);

//TODO: Watch out for unwanted references in the delegate lists.
}
}

~Collidable()
{
if (shape != null)
{
shape.ShapeChanged -= shapeChangedDelegate;
}
}

protected internal abstract IContactEventTriggerer EventTriggerer { get; }


Expand Down
8 changes: 6 additions & 2 deletions BEPUphysics/CollisionShapes/CollisionShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ public abstract class CollisionShape
///</summary>
public event Action<CollisionShape> ShapeChanged;

public void ClearShapeChanged()
{
ShapeChanged = null;
}

protected virtual void OnShapeChanged()
{
if (ShapeChanged != null)
ShapeChanged(this);
ShapeChanged?.Invoke(this);
}

public CollisionShape Duplicate()
Expand Down
17 changes: 17 additions & 0 deletions BEPUphysics/Entities/EntityBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,13 +445,30 @@ protected set
collisionInformation.Shape.ShapeChanged -= shapeChangedDelegate;
collisionInformation = value;
if (collisionInformation != null)
{
collisionInformation.Shape.ShapeChanged += shapeChangedDelegate;
}
//Entity constructors do their own initialization when the collision information changes.
//Might be able to condense it up here, but don't really need it right now.
//ShapeChangedHandler(collisionInformation.shape);
}
}

~Entity()
{
if (collisionInformation != null)
{
if (collisionInformation.shape != null)
{
collisionInformation.shape.ShapeChanged -= shapeChangedDelegate;
}
}
if (material != null)
{
material.MaterialChanged -= materialChangedDelegate;
}
}

//protected internal object locker = new object();
/////<summary>
///// Gets the synchronization object used by systems that need
Expand Down

0 comments on commit 4199964

Please sign in to comment.