@@ -282,25 +282,19 @@ pub fn get_rigid_body_mut<'a>(
282282 sim : & ' a mut SimulationSceneData ,
283283 sable_data : & SableSceneData ,
284284 id : LevelColliderID ,
285- ) -> & ' a mut RigidBody {
286- let handle = sable_data
287- . rigid_bodies
288- . get ( & id)
289- . expect ( "No rigid body for id" ) ;
290- & mut sim. rigid_body_set [ * handle]
285+ ) -> Option < & ' a mut RigidBody > {
286+ let handle = sable_data. rigid_bodies . get ( & id) ?;
287+ sim. rigid_body_set . get_mut ( * handle)
291288}
292289
293290#[ inline( always) ]
294291pub fn get_rigid_body < ' a > (
295292 sim : & ' a SimulationSceneData ,
296293 sable_data : & SableSceneData ,
297294 id : LevelColliderID ,
298- ) -> & ' a RigidBody {
299- let handle = sable_data
300- . rigid_bodies
301- . get ( & id)
302- . expect ( "No rigid body for id" ) ;
303- & sim. rigid_body_set [ * handle]
295+ ) -> Option < & ' a RigidBody > {
296+ let handle = sable_data. rigid_bodies . get ( & id) ?;
297+ sim. rigid_body_set . get ( * handle)
304298}
305299
306300#[ unsafe( no_mangle) ]
@@ -527,18 +521,22 @@ pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_get
527521 let sable_data = scene. sable_data . read ( ) . unwrap ( ) ;
528522 let sim_data = scene. sim_data . read ( ) . unwrap ( ) ;
529523
530- let rb: & RigidBody =
531- & sim_data. rigid_body_set [ sable_data. rigid_bodies [ & ( id as LevelColliderID ) ] ] ;
532-
533- let arr: [ jdouble ; 7 ] = [
534- rb. translation ( ) . x as jdouble ,
535- rb. translation ( ) . y as jdouble ,
536- rb. translation ( ) . z as jdouble ,
537- rb. rotation ( ) . x as jdouble ,
538- rb. rotation ( ) . y as jdouble ,
539- rb. rotation ( ) . z as jdouble ,
540- rb. rotation ( ) . w as jdouble ,
541- ] ;
524+ let arr: [ jdouble ; 7 ] = match sable_data
525+ . rigid_bodies
526+ . get ( & ( id as LevelColliderID ) )
527+ . and_then ( |body| sim_data. rigid_body_set . get ( * body) )
528+ {
529+ Some ( rb) => [
530+ rb. translation ( ) . x as jdouble ,
531+ rb. translation ( ) . y as jdouble ,
532+ rb. translation ( ) . z as jdouble ,
533+ rb. rotation ( ) . x as jdouble ,
534+ rb. rotation ( ) . y as jdouble ,
535+ rb. rotation ( ) . z as jdouble ,
536+ rb. rotation ( ) . w as jdouble ,
537+ ] ,
538+ None => [ 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 ] ,
539+ } ;
542540
543541 env. set_double_array_region ( & store, 0 , & arr) . unwrap ( ) ;
544542 } )
@@ -691,10 +689,9 @@ pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_rem
691689 let mut sable_data = scene. sable_data . write ( ) . unwrap ( ) ;
692690
693691 sable_data. level_colliders . remove ( & ( id as LevelColliderID ) ) ;
694- let handle = sable_data
695- . rigid_bodies
696- . remove ( & ( id as LevelColliderID ) )
697- . expect ( "No rigid body for id" ) ;
692+ let Some ( handle) = sable_data. rigid_bodies . remove ( & ( id as LevelColliderID ) ) else {
693+ return ;
694+ } ;
698695
699696 let mut sim_data = scene. sim_data . write ( ) . unwrap ( ) ;
700697
@@ -1112,7 +1109,13 @@ pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_set
11121109 let sable_data = scene. sable_data . read ( ) . unwrap ( ) ;
11131110 let mut sim_data = scene. sim_data . write ( ) . unwrap ( ) ;
11141111
1115- let rb = & mut sim_data. rigid_body_set [ sable_data. rigid_bodies [ & ( id as LevelColliderID ) ] ] ;
1112+ let Some ( rb) = sable_data
1113+ . rigid_bodies
1114+ . get ( & ( id as LevelColliderID ) )
1115+ . and_then ( |body| sim_data. rigid_body_set . get_mut ( * body) )
1116+ else {
1117+ return ;
1118+ } ;
11161119
11171120 rb. set_additional_mass_properties (
11181121 MassProperties :: with_inertia_matrix ( Vec3 :: ZERO , mass as Real , inertia_tensor. into ( ) ) ,
@@ -1142,7 +1145,13 @@ pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_tel
11421145 let sable_data = scene. sable_data . read ( ) . unwrap ( ) ;
11431146 let mut sim_data = scene. sim_data . write ( ) . unwrap ( ) ;
11441147
1145- let rb = & mut sim_data. rigid_body_set [ sable_data. rigid_bodies [ & ( id as LevelColliderID ) ] ] ;
1148+ let Some ( rb) = sable_data
1149+ . rigid_bodies
1150+ . get ( & ( id as LevelColliderID ) )
1151+ . and_then ( |body| sim_data. rigid_body_set . get_mut ( * body) )
1152+ else {
1153+ return ;
1154+ } ;
11461155
11471156 let mut pose = * rb. position ( ) ;
11481157 pose. translation = Vec3 :: new ( x as Real , y as Real , z as Real ) ;
@@ -1164,7 +1173,13 @@ pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_wak
11641173 with_handle ( handle, |scene| {
11651174 let sable_data = scene. sable_data . read ( ) . unwrap ( ) ;
11661175 let mut sim_data = scene. sim_data . write ( ) . unwrap ( ) ;
1167- let rb = & mut sim_data. rigid_body_set [ sable_data. rigid_bodies [ & ( id as LevelColliderID ) ] ] ;
1176+ let Some ( rb) = sable_data
1177+ . rigid_bodies
1178+ . get ( & ( id as LevelColliderID ) )
1179+ . and_then ( |body| sim_data. rigid_body_set . get_mut ( * body) )
1180+ else {
1181+ return ;
1182+ } ;
11681183 rb. wake_up ( true ) ;
11691184 } )
11701185}
@@ -1188,7 +1203,9 @@ pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_add
11881203 with_handle ( handle, |scene| {
11891204 let sable_data = scene. sable_data . read ( ) . unwrap ( ) ;
11901205 let mut sim_data = scene. sim_data . write ( ) . unwrap ( ) ;
1191- let rb = get_rigid_body_mut ( & mut sim_data, & sable_data, id as LevelColliderID ) ;
1206+ let Some ( rb) = get_rigid_body_mut ( & mut sim_data, & sable_data, id as LevelColliderID ) else {
1207+ return ;
1208+ } ;
11921209
11931210 if wake_up == 0 && rb. is_sleeping ( ) {
11941211 return ;
@@ -1288,10 +1305,9 @@ pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_app
12881305 let sable_data = scene. sable_data . read ( ) . unwrap ( ) ;
12891306 let mut sim_data = scene. sim_data . write ( ) . unwrap ( ) ;
12901307
1291- let body = sable_data
1292- . rigid_bodies
1293- . get ( & ( id as LevelColliderID ) )
1294- . unwrap ( ) ;
1308+ let Some ( body) = sable_data. rigid_bodies . get ( & ( id as LevelColliderID ) ) else {
1309+ return ;
1310+ } ;
12951311 let rb = & mut sim_data. rigid_body_set [ * body] ;
12961312
12971313 if wake_up == 0 && rb. is_sleeping ( ) {
@@ -1333,10 +1349,9 @@ pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_app
13331349 let sable_data = scene. sable_data . read ( ) . unwrap ( ) ;
13341350 let mut sim_data = scene. sim_data . write ( ) . unwrap ( ) ;
13351351
1336- let body = sable_data
1337- . rigid_bodies
1338- . get ( & ( id as LevelColliderID ) )
1339- . unwrap ( ) ;
1352+ let Some ( body) = sable_data. rigid_bodies . get ( & ( id as LevelColliderID ) ) else {
1353+ return ;
1354+ } ;
13401355 let rb = & mut sim_data. rigid_body_set [ * body] ;
13411356
13421357 if wake_up == 0 && rb. is_sleeping ( ) {
@@ -1370,10 +1385,9 @@ pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_get
13701385 let sable_data = scene. sable_data . read ( ) . unwrap ( ) ;
13711386 let sim_data = scene. sim_data . read ( ) . unwrap ( ) ;
13721387
1373- let body = sable_data
1374- . rigid_bodies
1375- . get ( & ( id as LevelColliderID ) )
1376- . unwrap ( ) ;
1388+ let Some ( body) = sable_data. rigid_bodies . get ( & ( id as LevelColliderID ) ) else {
1389+ return ;
1390+ } ;
13771391 let rb = & sim_data. rigid_body_set [ * body] ;
13781392
13791393 let vel = rb. linvel ( ) ;
@@ -1402,10 +1416,9 @@ pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_get
14021416 let sable_data = scene. sable_data . read ( ) . unwrap ( ) ;
14031417 let sim_data = scene. sim_data . read ( ) . unwrap ( ) ;
14041418
1405- let body = sable_data
1406- . rigid_bodies
1407- . get ( & ( id as LevelColliderID ) )
1408- . unwrap ( ) ;
1419+ let Some ( body) = sable_data. rigid_bodies . get ( & ( id as LevelColliderID ) ) else {
1420+ return ;
1421+ } ;
14091422 let rb = & sim_data. rigid_body_set [ * body] ;
14101423
14111424 let vel = rb. angvel ( ) ;
0 commit comments