From 6d97272420cd3c833284b1adf986e032f48afc77 Mon Sep 17 00:00:00 2001 From: En Yi Date: Tue, 15 Aug 2023 20:03:32 +0800 Subject: [PATCH] Fix missing grid bound checking in game systems --- scenes/game_systems.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scenes/game_systems.c b/scenes/game_systems.c index a14a0cd..9ca86cb 100644 --- a/scenes/game_systems.c +++ b/scenes/game_systems.c @@ -1331,6 +1331,8 @@ void update_tilemap_system(Scene_t* scene) tile_x2 = (p_ctransform->position.x + p_bbox->size.x - 1) / TILE_SIZE; tile_y2 = (p_ctransform->position.y + p_bbox->size.y - 1) / TILE_SIZE; } + tile_x2 = (tile_x2 >= tilemap.width) ? tilemap.width - 1 : tile_x2; + tile_y2 = (tile_y2 >= tilemap.height) ? tilemap.width - 1 : tile_y2; for (unsigned int tile_y = tile_y1; tile_y <= tile_y2; tile_y++) { @@ -1372,6 +1374,8 @@ void hitbox_update_system(Scene_t* scene) unsigned int tile_y1 = (hitbox_pos.y) / TILE_SIZE; unsigned int tile_x2 = (hitbox_pos.x + p_hitbox->boxes[i].width - 1) / TILE_SIZE; unsigned int tile_y2 = (hitbox_pos.y + p_hitbox->boxes[i].height - 1) / TILE_SIZE; + tile_x2 = (tile_x2 >= tilemap.width) ? tilemap.width - 1 : tile_x2; + tile_y2 = (tile_y2 >= tilemap.height) ? tilemap.width - 1 : tile_y2; for (unsigned int tile_y = tile_y1; tile_y <= tile_y2; tile_y++) {