File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -58,14 +58,22 @@ pub inline fn isValidBodyPointer(body: *const Body) bool {
5858/// Use `PhysicsSystem.getBodies()` to get all the bodies.
5959/// NOTE: This function is *not* protected by a lock, use with care!
6060pub inline fn tryGetBody (all_bodies : []const * const Body , body_id : BodyId ) ? * const Body {
61- const body = all_bodies [body_id & body_id_index_bits ];
61+ const index = body_id .indexBits ();
62+ if (index >= all_bodies .len ) {
63+ return null ;
64+ }
65+ const body = all_bodies [index ];
6266 return if (isValidBodyPointer (body ) and body .id == body_id ) body else null ;
6367}
6468/// Access a body, will return a `null` if the `body_id` is no longer valid.
6569/// Use `PhysicsSystem.getBodiesMut()` to get all the bodies.
6670/// NOTE: This function is *not* protected by a lock, use with care!
6771pub inline fn tryGetBodyMut (all_bodies : []const * Body , body_id : BodyId ) ? * Body {
68- const body = all_bodies [body_id & body_id_index_bits ];
72+ const index = body_id .indexBits ();
73+ if (index >= all_bodies .len ) {
74+ return null ;
75+ }
76+ const body = all_bodies [index ];
6977 return if (isValidBodyPointer (body ) and body .id == body_id ) body else null ;
7078}
7179
You can’t perform that action at this time.
0 commit comments