Skip to content

Commit

Permalink
[Physics] Prevent invalid state when component was added right after …
Browse files Browse the repository at this point in the history
…removal (stride3d#799)

* [Physics] Prevent invalid state when component was added right after removal

* Use a HashSet for faster search/remove
  • Loading branch information
manio143 committed Jul 23, 2020
1 parent ad0d94f commit 61b9c48
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sources/engine/Stride.Physics/Engine/PhysicsProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ protected override bool IsAssociatedDataValid(Entity entity, PhysicsComponent ph

protected override void OnEntityComponentAdding(Entity entity, PhysicsComponent component, AssociatedData data)
{
// Tagged for removal? If yes, cancel it
if (currentFrameRemovals.Remove(component))
return;

component.Attach(data);

var character = component as CharacterComponent;
Expand Down Expand Up @@ -149,7 +153,7 @@ private void ComponentRemoval(PhysicsComponent component)
component.Detach();
}

private readonly List<PhysicsComponent> currentFrameRemovals = new List<PhysicsComponent>();
private readonly HashSet<PhysicsComponent> currentFrameRemovals = new HashSet<PhysicsComponent>();

protected override void OnEntityComponentRemoved(Entity entity, PhysicsComponent component, AssociatedData data)
{
Expand Down

0 comments on commit 61b9c48

Please sign in to comment.