From a6ae7f02f0c79cfa0ecd4b296a897f8c83bfc96b Mon Sep 17 00:00:00 2001 From: peterino2 Date: Thu, 18 Sep 2025 09:05:12 -0700 Subject: [PATCH] fixed out of order deinit crash --- engine/physics/src/physicsSystem.zig | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/engine/physics/src/physicsSystem.zig b/engine/physics/src/physicsSystem.zig index 32c347f..8685a07 100644 --- a/engine/physics/src/physicsSystem.zig +++ b/engine/physics/src/physicsSystem.zig @@ -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);