diff options
author | kobewi <kobewi4e@gmail.com> | 2024-07-05 14:00:30 +0200 |
---|---|---|
committer | kobewi <kobewi4e@gmail.com> | 2024-07-05 14:00:30 +0200 |
commit | 267b5bca2336857df575499c6f15fcbd8fbf7902 (patch) | |
tree | 5027136010487d21e7e98d374c0e5f856ae12fc6 /editor | |
parent | 20ba2f00bd9199b675176a8e1ac151f96bfb5cfa (diff) | |
download | redot-engine-267b5bca2336857df575499c6f15fcbd8fbf7902.tar.gz |
Fix crash in tile physics editor
Diffstat (limited to 'editor')
-rw-r--r-- | editor/plugins/tiles/tile_data_editors.cpp | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/editor/plugins/tiles/tile_data_editors.cpp b/editor/plugins/tiles/tile_data_editors.cpp index e8a7b3b514..f985bbc629 100644 --- a/editor/plugins/tiles/tile_data_editors.cpp +++ b/editor/plugins/tiles/tile_data_editors.cpp @@ -139,9 +139,17 @@ void GenericTilePolygonEditor::_base_control_draw() { const Ref<StyleBox> focus_stylebox = get_theme_stylebox(SNAME("Focus"), EditorStringName(EditorStyles)); // Get the background data. - TileData *tile_data = background_atlas_source->get_tile_data(background_atlas_coords, background_alternative_id); - ERR_FAIL_NULL(tile_data); - Rect2 background_region = background_atlas_source->get_tile_texture_region(background_atlas_coords); + Rect2 background_region; + TileData *tile_data = nullptr; + + if (background_atlas_source.is_valid()) { + tile_data = background_atlas_source->get_tile_data(background_atlas_coords, background_alternative_id); + ERR_FAIL_NULL(tile_data); + background_region = background_atlas_source->get_tile_texture_region(background_atlas_coords); + } else { + // If no tile was selected yet, use default size. + background_region.size = tile_set->get_tile_size(); + } // Draw the focus rectangle. if (base_control->has_focus()) { @@ -157,11 +165,14 @@ void GenericTilePolygonEditor::_base_control_draw() { base_control->draw_set_transform_matrix(xform); // Draw fill rect under texture region. - Rect2 texture_rect(-background_region.size / 2 - tile_data->get_texture_origin(), background_region.size); + Rect2 texture_rect(-background_region.size / 2, background_region.size); + if (tile_data) { + texture_rect.position -= tile_data->get_texture_origin(); + } base_control->draw_rect(texture_rect, Color(1, 1, 1, 0.3)); // Draw the background. - if (background_atlas_source->get_texture().is_valid()) { + if (tile_data && background_atlas_source->get_texture().is_valid()) { Size2 region_size = background_region.size; if (tile_data->get_flip_h()) { region_size.x = -region_size.x; @@ -174,8 +185,13 @@ void GenericTilePolygonEditor::_base_control_draw() { // Compute and draw the grid area. Rect2 grid_area = Rect2(-base_tile_size / 2, base_tile_size); - grid_area.expand_to(-background_region.get_size() / 2 - tile_data->get_texture_origin()); - grid_area.expand_to(background_region.get_size() / 2 - tile_data->get_texture_origin()); + if (tile_data) { + grid_area.expand_to(-background_region.get_size() / 2 - tile_data->get_texture_origin()); + grid_area.expand_to(background_region.get_size() / 2 - tile_data->get_texture_origin()); + } else { + grid_area.expand_to(-background_region.get_size() / 2); + grid_area.expand_to(background_region.get_size() / 2); + } base_control->draw_rect(grid_area, Color(1, 1, 1, 0.3), false); // Draw grid. |