@@ -708,6 +708,9 @@ pub fn init_colliders(
708708 let context = & mut * context;
709709 let scale = context. physics_scale ;
710710
711+ let mut sorted_colliders: Vec < ColliderComponents > = colliders. iter ( ) . collect ( ) ;
712+ sorted_colliders. sort_by_key ( |f| f. 0 ) ;
713+
711714 for (
712715 entity,
713716 shape,
@@ -721,7 +724,7 @@ pub fn init_colliders(
721724 collision_groups,
722725 solver_groups,
723726 contact_force_event_threshold,
724- ) in colliders . iter ( )
727+ ) in sorted_colliders
725728 {
726729 let mut scaled_shape = shape. clone ( ) ;
727730 scaled_shape. set_scale ( shape. scale / scale, config. scaled_shape_subdivision ) ;
@@ -824,6 +827,9 @@ pub fn init_rigid_bodies(
824827) {
825828 let scale = context. physics_scale ;
826829
830+ let mut sorted_rigid_bodies: Vec < RigidBodyComponents > = rigid_bodies. iter ( ) . collect ( ) ;
831+ sorted_rigid_bodies. sort_by_key ( |f| f. 0 ) ;
832+
827833 for (
828834 entity,
829835 rb,
@@ -838,7 +844,7 @@ pub fn init_rigid_bodies(
838844 dominance,
839845 sleep,
840846 damping,
841- ) in rigid_bodies . iter ( )
847+ ) in sorted_rigid_bodies
842848 {
843849 let mut builder = RigidBodyBuilder :: new ( ( * rb) . into ( ) ) ;
844850 if let Some ( transform) = transform {
@@ -965,7 +971,10 @@ pub fn init_joints(
965971 let context = & mut * context;
966972 let scale = context. physics_scale ;
967973
968- for ( entity, joint) in impulse_joints. iter ( ) {
974+ let mut sorted_impulse_joints: Vec < ( Entity , & ImpulseJoint ) > = impulse_joints. iter ( ) . collect ( ) ;
975+ sorted_impulse_joints. sort_by_key ( |f| f. 0 ) ;
976+
977+ for ( entity, joint) in sorted_impulse_joints {
969978 let mut target = None ;
970979 let mut body_entity = entity;
971980 while target. is_none ( ) {
@@ -989,7 +998,11 @@ pub fn init_joints(
989998 }
990999 }
9911000
992- for ( entity, joint) in multibody_joints. iter ( ) {
1001+ let mut sorted_multibody_joints: Vec < ( Entity , & MultibodyJoint ) > =
1002+ multibody_joints. iter ( ) . collect ( ) ;
1003+ sorted_multibody_joints. sort_by_key ( |f| f. 0 ) ;
1004+
1005+ for ( entity, joint) in sorted_multibody_joints {
9931006 let target = context. entity2body . get ( & entity) ;
9941007
9951008 if let ( Some ( target) , Some ( source) ) = ( target, context. entity2body . get ( & joint. parent ) ) {
@@ -1067,7 +1080,10 @@ pub fn sync_removals(
10671080 /*
10681081 * Collider removal detection.
10691082 */
1070- for entity in removed_colliders. iter ( ) {
1083+ let mut sorted_removed_colliders: Vec < Entity > = removed_colliders. iter ( ) . collect ( ) ;
1084+ sorted_removed_colliders. sort ( ) ;
1085+
1086+ for entity in sorted_removed_colliders {
10711087 if let Some ( handle) = context. entity2collider . remove ( & entity) {
10721088 context
10731089 . colliders
@@ -1076,7 +1092,10 @@ pub fn sync_removals(
10761092 }
10771093 }
10781094
1079- for entity in orphan_colliders. iter ( ) {
1095+ let mut sorted_orphan_colliders: Vec < Entity > = orphan_colliders. iter ( ) . collect ( ) ;
1096+ sorted_orphan_colliders. sort ( ) ;
1097+
1098+ for entity in sorted_orphan_colliders {
10801099 if let Some ( handle) = context. entity2collider . remove ( & entity) {
10811100 context
10821101 . colliders
0 commit comments