From 0a119411c06468871b132b3e8b263b58bffa3ae1 Mon Sep 17 00:00:00 2001 From: Tom Solberg Date: Wed, 27 Sep 2023 15:50:36 +0200 Subject: [PATCH 1/2] Do not manually free materials for shapes --- Cargo.toml | 1 + physx/src/material.rs | 2 +- physx/src/shape.rs | 3 -- physx/tests/bug-180.rs | 67 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 physx/tests/bug-180.rs diff --git a/Cargo.toml b/Cargo.toml index a630eeb8..21572104 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,3 @@ [workspace] +resolver = "2" members = ["physx", "physx-sys", "physx-sys/pxbind"] diff --git a/physx/src/material.rs b/physx/src/material.rs index df331182..0019a736 100644 --- a/physx/src/material.rs +++ b/physx/src/material.rs @@ -140,7 +140,7 @@ pub trait Material: Class + UserData { } /// Set the restitution. - /// - Restitution must be in [0.0 ..= 1.0], values outside tyhe range are clamped. + /// - Restitution must be in [0.0 ..= 1.0], values outside the range are clamped. /// - A reitution of 0.0 minimizes bouncing, higher values mean more bounce. #[inline] fn set_restitution(&mut self, mut restitution: f32) { diff --git a/physx/src/shape.rs b/physx/src/shape.rs index 039a00db..00f70fae 100644 --- a/physx/src/shape.rs +++ b/physx/src/shape.rs @@ -62,9 +62,6 @@ unsafe impl UserData for PxShape { impl Drop for PxShape { fn drop(&mut self) { unsafe { - for material in self.get_materials_mut() { - drop_in_place(material as *mut _); - } drop_in_place(self.get_user_data_mut()); use crate::base::RefCounted; self.release(); diff --git a/physx/tests/bug-180.rs b/physx/tests/bug-180.rs new file mode 100644 index 00000000..3e77b61c --- /dev/null +++ b/physx/tests/bug-180.rs @@ -0,0 +1,67 @@ +use physx::{base::RefCounted, prelude::*}; + +type PxMaterial = physx::material::PxMaterial<()>; +type PxShape = physx::shape::PxShape<(), PxMaterial>; +type PxArticulationLink = physx::articulation_link::PxArticulationLink<(), PxShape>; +type PxRigidStatic = physx::rigid_static::PxRigidStatic<(), PxShape>; +type PxRigidDynamic = physx::rigid_dynamic::PxRigidDynamic<(), PxShape>; + +/// Next up, the simulation event callbacks need to be defined, and possibly an +/// allocator callback as well. +struct OnCollision; +impl CollisionCallback for OnCollision { + fn on_collision( + &mut self, + _header: &physx_sys::PxContactPairHeader, + _pairs: &[physx_sys::PxContactPair], + ) { + } +} +struct OnTrigger; +impl TriggerCallback for OnTrigger { + fn on_trigger(&mut self, _pairs: &[physx_sys::PxTriggerPair]) {} +} + +struct OnConstraintBreak; +impl ConstraintBreakCallback for OnConstraintBreak { + fn on_constraint_break(&mut self, _constraints: &[physx_sys::PxConstraintInfo]) {} +} +struct OnWakeSleep; +impl WakeSleepCallback for OnWakeSleep { + fn on_wake_sleep( + &mut self, + _actors: &[&physx::actor::ActorMap], + _is_waking: bool, + ) { + } +} + +struct OnAdvance; +impl AdvanceCallback for OnAdvance { + fn on_advance( + &self, + _actors: &[&physx::rigid_body::RigidBodyMap], + _transforms: &[PxTransform], + ) { + } +} + +#[test] +fn test_double_free() { + let mut physics = PhysicsFoundation::<_, PxShape>::default(); + + let mut material = physics.create_material(0.5, 0.5, 0.6, ()).unwrap(); + let geometry = PxBoxGeometry::new(1., 1., 1.); + let flags = + ShapeFlags::SceneQueryShape | ShapeFlags::SimulationShape | ShapeFlags::Visualization; + + let shape = physics + .create_shape(&geometry, &mut [&mut material], false, flags, ()) + .unwrap(); + + assert_eq!(material.get_reference_count(), 2); + drop(shape); + + assert_eq!(material.get_reference_count(), 1); + drop(material); +} From 49a45978baca6bdf4793200b9d8e459067628570 Mon Sep 17 00:00:00 2001 From: Tom Solberg Date: Thu, 5 Oct 2023 11:25:09 +0200 Subject: [PATCH 2/2] remove unnecessary junk --- physx/tests/bug-180.rs | 43 ------------------------------------------ 1 file changed, 43 deletions(-) diff --git a/physx/tests/bug-180.rs b/physx/tests/bug-180.rs index 3e77b61c..7b6adcb1 100644 --- a/physx/tests/bug-180.rs +++ b/physx/tests/bug-180.rs @@ -2,49 +2,6 @@ use physx::{base::RefCounted, prelude::*}; type PxMaterial = physx::material::PxMaterial<()>; type PxShape = physx::shape::PxShape<(), PxMaterial>; -type PxArticulationLink = physx::articulation_link::PxArticulationLink<(), PxShape>; -type PxRigidStatic = physx::rigid_static::PxRigidStatic<(), PxShape>; -type PxRigidDynamic = physx::rigid_dynamic::PxRigidDynamic<(), PxShape>; - -/// Next up, the simulation event callbacks need to be defined, and possibly an -/// allocator callback as well. -struct OnCollision; -impl CollisionCallback for OnCollision { - fn on_collision( - &mut self, - _header: &physx_sys::PxContactPairHeader, - _pairs: &[physx_sys::PxContactPair], - ) { - } -} -struct OnTrigger; -impl TriggerCallback for OnTrigger { - fn on_trigger(&mut self, _pairs: &[physx_sys::PxTriggerPair]) {} -} - -struct OnConstraintBreak; -impl ConstraintBreakCallback for OnConstraintBreak { - fn on_constraint_break(&mut self, _constraints: &[physx_sys::PxConstraintInfo]) {} -} -struct OnWakeSleep; -impl WakeSleepCallback for OnWakeSleep { - fn on_wake_sleep( - &mut self, - _actors: &[&physx::actor::ActorMap], - _is_waking: bool, - ) { - } -} - -struct OnAdvance; -impl AdvanceCallback for OnAdvance { - fn on_advance( - &self, - _actors: &[&physx::rigid_body::RigidBodyMap], - _transforms: &[PxTransform], - ) { - } -} #[test] fn test_double_free() {