Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash in tile physics editor #93971

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions editor/plugins/tiles/tile_data_editors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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;
Expand All @@ -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.
Expand Down
Loading