From 42c672afd65020e86c522b5bbfc8ed4c43b3984b Mon Sep 17 00:00:00 2001 From: jsjtxietian Date: Thu, 28 Dec 2023 10:42:37 +0800 Subject: [PATCH] Fix infinite loop when calculating zoom level if tile_size * max_zoom < default --- editor/plugins/tiles/tile_data_editors.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/editor/plugins/tiles/tile_data_editors.cpp b/editor/plugins/tiles/tile_data_editors.cpp index 221833d4502..d581599c967 100644 --- a/editor/plugins/tiles/tile_data_editors.cpp +++ b/editor/plugins/tiles/tile_data_editors.cpp @@ -719,11 +719,19 @@ void GenericTilePolygonEditor::set_tile_set(Ref p_tile_set) { Vector2 zoomed_tile = editor_zoom_widget->get_zoom() * tile_set->get_tile_size(); while (zoomed_tile.y < default_control_y_size) { editor_zoom_widget->set_zoom_by_increments(6, false); - zoomed_tile = editor_zoom_widget->get_zoom() * tile_set->get_tile_size(); + float current_zoom = editor_zoom_widget->get_zoom(); + zoomed_tile = current_zoom * tile_set->get_tile_size(); + if (Math::is_equal_approx(current_zoom, editor_zoom_widget->get_max_zoom())) { + break; + } } while (zoomed_tile.y > default_control_y_size) { editor_zoom_widget->set_zoom_by_increments(-6, false); - zoomed_tile = editor_zoom_widget->get_zoom() * tile_set->get_tile_size(); + float current_zoom = editor_zoom_widget->get_zoom(); + zoomed_tile = current_zoom * tile_set->get_tile_size(); + if (Math::is_equal_approx(current_zoom, editor_zoom_widget->get_min_zoom())) { + break; + } } editor_zoom_widget->set_zoom_by_increments(-6, false); _zoom_changed();