Merge pull request #86568 from jsjtxietian/fix-infinite-loop-tile

Fix potential infinite loop when calculating tile editor zoom level
This commit is contained in:
Rémi Verschelde 2024-01-08 11:55:30 +01:00
commit dd487ebb0b
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 10 additions and 2 deletions

View File

@ -719,11 +719,19 @@ void GenericTilePolygonEditor::set_tile_set(Ref<TileSet> 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();