summaryrefslogtreecommitdiffstats
path: root/editor/plugins/tiles
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-07-05 15:07:54 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-07-05 15:07:54 +0200
commitc9ca3aa9aba1f213e5eaa31f98183d3a6910d19f (patch)
treefb817021c6ee19b3f9fd3acc60322c09e21feac7 /editor/plugins/tiles
parentf1749c691f8c33d094b5b6dddb2a7b2bb4456c8e (diff)
parent267b5bca2336857df575499c6f15fcbd8fbf7902 (diff)
downloadredot-engine-c9ca3aa9aba1f213e5eaa31f98183d3a6910d19f.tar.gz
Merge pull request #93971 from KoBeWi/casually_crashing_in_background
Fix crash in tile physics editor
Diffstat (limited to 'editor/plugins/tiles')
-rw-r--r--editor/plugins/tiles/tile_data_editors.cpp30
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.