fixed out of order deinit crash

This commit is contained in:
peterino2 2025-09-18 09:05:12 -07:00
parent e78d01b547
commit a6ae7f02f0
1 changed files with 14 additions and 12 deletions

View File

@ -239,10 +239,22 @@ pub const PhysicsRuntime = struct {
pub fn deinit(self: *@This()) void {
const allocator = self.allocator;
self.system.optimizeBroadPhase();
for (PhysicsCharacter.BaseContainer.list.items) |physChar| {
physChar.deinit();
}
// self.system.update(0.01, .{}) catch {};
{
const interface = self.system.getBodyInterfaceMut();
var iterator = self.idToEntity.keyIterator();
while (iterator.next()) |bodyId| {
self.system.optimizeBroadPhase();
interface.removeAndDestroyBody(bodyId.*);
}
}
{
var iterator = self.shapes.iterator();
while (iterator.next()) |n| {
@ -250,18 +262,8 @@ pub const PhysicsRuntime = struct {
}
}
self.system.update(0.01, .{}) catch {};
{
const interface = self.system.getBodyInterfaceMut();
var iterator = self.idToEntity.keyIterator();
while (iterator.next()) |bodyId| {
interface.removeAndDestroyBody(bodyId.*);
}
}
self.bodyIdsToDestroy.deinit(self.allocator);
self.system.update(0.01, .{}) catch {};
// self.system.update(0.01, .{}) catch {};
self.idToEntity.deinit(self.allocator);
// core.undefineComponent(PhysicsCharacter);