Skip to content

Commit 4d092f5

Browse files
committed
fix
1 parent 0266eaa commit 4d092f5

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

src/physics/jolt/back/operators/creator.mjs

+23-10
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ class Creator {
676676
const id = cb.read(BUFFER_READ_INT32);
677677
const bodyInterface = backend.bodyInterface;
678678

679+
let ok = true;
679680
let body, bodyID;
680681
if (id < 0) {
681682
body = bodyInterface.CreateBody(bodyCreationSettings);
@@ -686,16 +687,26 @@ class Creator {
686687
// skip the check for production build
687688
if ($_DEBUG) {
688689
const eb = backend.physicsSystem.GetBodyLockInterfaceNoLock().TryGetBody(bodyID);
689-
if (eb?.IsInBroadPhase()) {
690-
Debug.warn('Trying to add a new body with a custom ID that already belongs ' +
691-
'to another existing body in the physics world. Skipping body creation.');
690+
if (Jolt.getPointer(eb)) {
691+
Debug.warn(`Trying to add a new body with a custom ID (${id}) that already ` +
692+
'belongs to another existing body in the physics world. Skipping body ' +
693+
'creation.');
694+
ok = false;
692695
}
693696
}
694697

695698
body = bodyInterface.CreateBodyWithID(bodyID, bodyCreationSettings);
699+
700+
if ($_DEBUG && !Jolt.getPointer(body)) {
701+
Debug.warn(`Failed to create a body with custom id: ${id}`);
702+
return false;
703+
}
704+
}
705+
706+
if (ok) {
707+
bodyInterface.AddBody(bodyID, Jolt.EActivation_Activate);
696708
}
697709

698-
bodyInterface.AddBody(bodyID, Jolt.EActivation_Activate);
699710
body.isometryUpdate = cb.read(BUFFER_READ_UINT8);
700711

701712
if ($_DEBUG) {
@@ -707,13 +718,15 @@ class Creator {
707718
Jolt.destroy(shapeSettings);
708719
Jolt.destroy(bodyCreationSettings);
709720

710-
if (backend.config.useMotionStates &&
711-
useMotionState &&
712-
(jmt === Jolt.EMotionType_Dynamic || jmt === Jolt.EMotionType_Kinematic)) {
713-
body.motionState = new MotionState(body);
714-
}
721+
if (ok) {
722+
if (backend.config.useMotionStates &&
723+
useMotionState &&
724+
(jmt === Jolt.EMotionType_Dynamic || jmt === Jolt.EMotionType_Kinematic)) {
725+
body.motionState = new MotionState(body);
726+
}
715727

716-
backend.tracker.add(body, index);
728+
backend.tracker.add(body, index);
729+
}
717730

718731
return true;
719732
}

0 commit comments

Comments
 (0)