Skip to content

Commit c9ca3aa

Browse files
committed
Merge pull request godotengine#93971 from KoBeWi/casually_crashing_in_background
Fix crash in tile physics editor
2 parents f1749c6 + 267b5bc commit c9ca3aa

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

editor/plugins/tiles/tile_data_editors.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,17 @@ void GenericTilePolygonEditor::_base_control_draw() {
139139
const Ref<StyleBox> focus_stylebox = get_theme_stylebox(SNAME("Focus"), EditorStringName(EditorStyles));
140140

141141
// Get the background data.
142-
TileData *tile_data = background_atlas_source->get_tile_data(background_atlas_coords, background_alternative_id);
143-
ERR_FAIL_NULL(tile_data);
144-
Rect2 background_region = background_atlas_source->get_tile_texture_region(background_atlas_coords);
142+
Rect2 background_region;
143+
TileData *tile_data = nullptr;
144+
145+
if (background_atlas_source.is_valid()) {
146+
tile_data = background_atlas_source->get_tile_data(background_atlas_coords, background_alternative_id);
147+
ERR_FAIL_NULL(tile_data);
148+
background_region = background_atlas_source->get_tile_texture_region(background_atlas_coords);
149+
} else {
150+
// If no tile was selected yet, use default size.
151+
background_region.size = tile_set->get_tile_size();
152+
}
145153

146154
// Draw the focus rectangle.
147155
if (base_control->has_focus()) {
@@ -157,11 +165,14 @@ void GenericTilePolygonEditor::_base_control_draw() {
157165
base_control->draw_set_transform_matrix(xform);
158166

159167
// Draw fill rect under texture region.
160-
Rect2 texture_rect(-background_region.size / 2 - tile_data->get_texture_origin(), background_region.size);
168+
Rect2 texture_rect(-background_region.size / 2, background_region.size);
169+
if (tile_data) {
170+
texture_rect.position -= tile_data->get_texture_origin();
171+
}
161172
base_control->draw_rect(texture_rect, Color(1, 1, 1, 0.3));
162173

163174
// Draw the background.
164-
if (background_atlas_source->get_texture().is_valid()) {
175+
if (tile_data && background_atlas_source->get_texture().is_valid()) {
165176
Size2 region_size = background_region.size;
166177
if (tile_data->get_flip_h()) {
167178
region_size.x = -region_size.x;
@@ -174,8 +185,13 @@ void GenericTilePolygonEditor::_base_control_draw() {
174185

175186
// Compute and draw the grid area.
176187
Rect2 grid_area = Rect2(-base_tile_size / 2, base_tile_size);
177-
grid_area.expand_to(-background_region.get_size() / 2 - tile_data->get_texture_origin());
178-
grid_area.expand_to(background_region.get_size() / 2 - tile_data->get_texture_origin());
188+
if (tile_data) {
189+
grid_area.expand_to(-background_region.get_size() / 2 - tile_data->get_texture_origin());
190+
grid_area.expand_to(background_region.get_size() / 2 - tile_data->get_texture_origin());
191+
} else {
192+
grid_area.expand_to(-background_region.get_size() / 2);
193+
grid_area.expand_to(background_region.get_size() / 2);
194+
}
179195
base_control->draw_rect(grid_area, Color(1, 1, 1, 0.3), false);
180196

181197
// Draw grid.

0 commit comments

Comments
 (0)