From 73c5e170260638cc566cba2689ea570caee39251 Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Tue, 16 Sep 2025 16:58:02 -0400 Subject: pke: major object lifetime overhaul. Added pke-test-load-unload to ensure objects are managed as expected. --- src/physics.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/physics.cpp') diff --git a/src/physics.cpp b/src/physics.cpp index 34cfbed..fe0385c 100644 --- a/src/physics.cpp +++ b/src/physics.cpp @@ -22,10 +22,11 @@ struct AllocedData { }; pk_arr_t bulletAllocs{}; +btHashedOverlappingPairCache *overlappingPairCache = nullptr; btDefaultCollisionConfiguration *btConfiguration = nullptr; btCollisionDispatcher *btDispatcher = nullptr; -btBroadphaseInterface *btBroadphase = nullptr; -btConstraintSolver *btSolver = nullptr; +btDbvtBroadphase *btBroadphase = nullptr; +btSequentialImpulseConstraintSolver *btSolver = nullptr; struct EntityCollision { CompInstance *a, *b; @@ -111,7 +112,7 @@ void Physics_Init() { btBroadphase = pk_new(MemBkt_Bullet); #if 1 - btHashedOverlappingPairCache *overlappingPairCache = pk_new(MemBkt_Bullet); + overlappingPairCache = pk_new(MemBkt_Bullet); overlappingPairCache->setOverlapFilterCallback(&collisionHandlerStruct); new (btBroadphase) btDbvtBroadphase(overlappingPairCache); #else @@ -136,7 +137,22 @@ int32_t Physics_Tick(double delta) { void Physics_Teardown() { pk_arr_reset(&collisionsThisTick); - pk_delete(BtDynamicsWorld, MemBkt_Bullet); + if (BtDynamicsWorld != nullptr) + pk_delete(BtDynamicsWorld, MemBkt_Bullet); + if (overlappingPairCache != nullptr) + pk_delete(overlappingPairCache, MemBkt_Bullet); + if (btConfiguration != nullptr) + pk_delete(btConfiguration, MemBkt_Bullet); + if (btSolver != nullptr) + pk_delete(btSolver, MemBkt_Bullet); + if (btDispatcher != nullptr) + pk_delete(btDispatcher, MemBkt_Bullet); + if (btBroadphase != nullptr) + pk_delete(btBroadphase, MemBkt_Bullet); + btConfiguration = nullptr; + btSolver = nullptr; + btBroadphase = nullptr; + btDispatcher = nullptr; BtDynamicsWorld = nullptr; // TODO should we manually delete each bullet alloc? // or just drop? -- cgit v1.2.3