@@ -676,6 +676,7 @@ class Creator {
676
676
const id = cb . read ( BUFFER_READ_INT32 ) ;
677
677
const bodyInterface = backend . bodyInterface ;
678
678
679
+ let ok = true ;
679
680
let body , bodyID ;
680
681
if ( id < 0 ) {
681
682
body = bodyInterface . CreateBody ( bodyCreationSettings ) ;
@@ -686,16 +687,26 @@ class Creator {
686
687
// skip the check for production build
687
688
if ( $_DEBUG ) {
688
689
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 ;
692
695
}
693
696
}
694
697
695
698
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 ) ;
696
708
}
697
709
698
- bodyInterface . AddBody ( bodyID , Jolt . EActivation_Activate ) ;
699
710
body . isometryUpdate = cb . read ( BUFFER_READ_UINT8 ) ;
700
711
701
712
if ( $_DEBUG ) {
@@ -707,13 +718,15 @@ class Creator {
707
718
Jolt . destroy ( shapeSettings ) ;
708
719
Jolt . destroy ( bodyCreationSettings ) ;
709
720
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
+ }
715
727
716
- backend . tracker . add ( body , index ) ;
728
+ backend . tracker . add ( body , index ) ;
729
+ }
717
730
718
731
return true ;
719
732
}
0 commit comments