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..7b6adcb1 --- /dev/null +++ b/physx/tests/bug-180.rs @@ -0,0 +1,24 @@ +use physx::{base::RefCounted, prelude::*}; + +type PxMaterial = physx::material::PxMaterial<()>; +type PxShape = physx::shape::PxShape<(), PxMaterial>; + +#[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); +}