I would have assumed that a simple Free or QueueFree on a PhysicsBody3D would delete all added shapes and their owners, children and other things related to them.
Even with following code I still get leaked things:
public override void _Ready()
{
var _physicsBody3D = new StaticBody3D();
var shape = new BoxShape3D();
var colShape = new CollisionShape3D()
{
Name = "collision_shape",
Shape = shape
};
var owner = new GodotObject();
uint ownerId = _physicsBody3D.CreateShapeOwner(owner);
_physicsBody3D.ShapeOwnerAddShape(ownerId, colShape.Shape);
Exit();
}
private void Exit()
{
SceneTree tree = GetTree();
RemoveAllShapes();
_physicsBody3D?.Free();
tree.ToSignal(
tree, SceneTree.SignalName.ProcessFrame
).OnCompleted(
() => tree.Quit()
);
}
private void RemoveAllShapes()
{
if (_physicsBody3D != null)
{
foreach (uint shapeOwner in _physicsBody3D.GetShapeOwners().Select(v => (uint)v))
{
var owner = _physicsBody3D.ShapeOwnerGetOwner(shapeOwner);
_physicsBody3D.ShapeOwnerClearShapes(shapeOwner);
_physicsBody3D.RemoveShapeOwner(shapeOwner);
owner.Free();
}
}
}
What do I need to do to ensure that the shapes are properly deleted?
I get the following error with the above code after the program was automatically terminated in the next frame:
ERROR: 1 RID allocations of type 'P11GodotBody3D' were leaked at exit.
ERROR: 1 RID allocations of type 'P12GodotShape3D' were leaked at exit.
WARNING: ObjectDB instances leaked at exit (run with --verbose for details).
at: cleanup (core/object/object.cpp:2047)
Godot Version: v4.1.1.stable.mono.official [bd6af8e0e]
Thanks