diff --git a/src/game_interpreter.cpp b/src/game_interpreter.cpp index 2e32757dc9..6657dd0250 100644 --- a/src/game_interpreter.cpp +++ b/src/game_interpreter.cpp @@ -4102,6 +4102,8 @@ bool Game_Interpreter::CommandManiacGetGameInfo(lcf::rpg::EventCommand const& co tile_coords.w = ValueOrVariableBitfield(com.parameters[0], 3, com.parameters[5]); tile_coords.h = ValueOrVariableBitfield(com.parameters[0], 4, com.parameters[6]); + if (tile_coords.w <= 0 || tile_coords.h <= 0) return true; + auto tiles = Game_Map::GetTilesIdAt(tile_coords.x, tile_coords.y, tile_coords.w, tile_coords.h, tile_layer); for (int i = 0; i < tile_coords.w * tile_coords.h; i++) { diff --git a/src/game_map.cpp b/src/game_map.cpp index 4c72959cab..dab3f8354e 100644 --- a/src/game_map.cpp +++ b/src/game_map.cpp @@ -1886,6 +1886,10 @@ void Game_Map::ReplaceTileAt(int x, int y, int new_id, int layer) { } int Game_Map::GetTileIdAt(int x, int y, int layer, bool chipIdOrIndex) { + if (x < 0 || x >= map->width || y < 0 || y >= map->height) { + return 0; // Return 0 for out-of-bounds coordinates + } + auto pos = x + y * map->width; auto& layer_vec = layer >= 1 ? map->upper_layer : map->lower_layer;