Skip to content

Commit a9f6aa1

Browse files
committed
fixed potential crash when joint is initializing earlier than bodies
1 parent 4018cd4 commit a9f6aa1

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/scene/graph/physics.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,24 +1532,24 @@ impl PhysicsWorld {
15321532
let body2_handle = joint.body2();
15331533
let params = joint.params().clone();
15341534

1535-
// A native joint can be created iff both rigid bodies are correctly assigned.
1535+
// A native joint can be created iff both rigid bodies are correctly assigned and their respective
1536+
// native bodies exists.
15361537
if let (Some(body1), Some(body2)) = (
1537-
nodes
1538-
.try_borrow(body1_handle)
1539-
.and_then(|n| n.cast::<scene::rigidbody::RigidBody>()),
1540-
nodes
1541-
.try_borrow(body2_handle)
1542-
.and_then(|n| n.cast::<scene::rigidbody::RigidBody>()),
1538+
nodes.try_borrow(body1_handle).and_then(|n| {
1539+
n.cast::<scene::rigidbody::RigidBody>()
1540+
.filter(|b| self.bodies.set.get(b.native.get()).is_some())
1541+
}),
1542+
nodes.try_borrow(body2_handle).and_then(|n| {
1543+
n.cast::<scene::rigidbody::RigidBody>()
1544+
.filter(|b| self.bodies.set.get(b.native.get()).is_some())
1545+
}),
15431546
) {
15441547
// Calculate local frames first.
15451548
let (local_frame1, local_frame2) = calculate_local_frames(joint, body1, body2);
15461549

15471550
let native_body1 = body1.native.get();
15481551
let native_body2 = body2.native.get();
15491552

1550-
assert!(self.bodies.set.get(native_body1).is_some());
1551-
assert!(self.bodies.set.get(native_body2).is_some());
1552-
15531553
let mut native_joint = convert_joint_params(params, local_frame1, local_frame2);
15541554
native_joint.contacts_enabled = joint.is_contacts_enabled();
15551555
let native_handle =

0 commit comments

Comments
 (0)