bepu / bepuphysics2

Pure C# 3D real time physics simulation library, now with a higher version number.
Apache License 2.0
2.25k stars 261 forks source link

Remove Bodies are broken #243

Closed Paulius0706 closed 1 year ago

Paulius0706 commented 1 year ago

I find that bodies not removed from simulation even if you try remove it. But body handler are not accesable after Simulation.Bodies.Remove(...).

if (!ShapesDir.boxShapes.ContainsKey(size)) ShapesDir.boxShapes.Add(size, Game.physicsSpace.Shapes.Add(new Box(1, 
1, 1)));
BodyInertia bodyInertia = new Box(size.X, size.Y, size.Z).ComputeInertia(mass);
this.bodyHandle = Game.physicsSpace.Bodies.Add(
BodyDescription.CreateDynamic(
new RigidPose(Adapter.Convert(new Vector(0,0,10)), Adapter.Convert(new Quaternion(0,0,0))),
bodyInertia,
new CollidableDescription(ShapesDir.boxShapes[size],size.Length + 0.1f),
new BodyActivityDescription(0.01f)));
this.bodyReference = Game.physicsSpace.Bodies.GetBodyReference(bodyHandle);
this.bodyReference.Awake = true;
Game.physicsSpace.Bodies.Remove(bodyHandle); // After this code executed it will not be destroyded
if (Game.physicsSpace.Bodies.BodyExists(bodyHandle))
{ Console.WriteLine("\n\n\n\n\n\n \n\n\n\n\n\n " + "handle still exist");}
RossNordby commented 1 year ago

I can't reproduce that in the demos; could you try writing a minimal reproducing example in the demos project for me to look at?

Worth noting that BodyHandle is not currently versioned. If you keep a BodyHandle around beyond its lifespan, it could end up pointing to another body later when more bodies are added.

Paulius0706 commented 1 year ago

Sorry it was my fault. When i wanted to weld rigs and I created invisible rig that dont delete by itself because this rig is cloting away in my code. Thanks for sugesssion for creating demo it helped And sorry for wasted time