Prevent crash and error spam related to Sprite2D with a region

This commit is contained in:
Yuri Sizov 2023-11-02 13:42:55 +01:00
parent da0b1eb128
commit 111a5e90da
3 changed files with 40 additions and 43 deletions

View file

@ -54,7 +54,7 @@ Transform2D TextureRegionEditor::_get_offset_transform() const {
}
void TextureRegionEditor::_texture_preview_draw() {
Ref<Texture2D> object_texture = _get_edited_object_texture();
const Ref<Texture2D> object_texture = _get_edited_object_texture();
if (object_texture.is_null()) {
return;
}
@ -68,7 +68,7 @@ void TextureRegionEditor::_texture_preview_draw() {
}
void TextureRegionEditor::_texture_overlay_draw() {
Ref<Texture2D> object_texture = _get_edited_object_texture();
const Ref<Texture2D> object_texture = _get_edited_object_texture();
if (object_texture.is_null()) {
return;
}
@ -746,7 +746,7 @@ void TextureRegionEditor::_update_autoslice() {
autoslice_is_dirty = false;
autoslice_cache.clear();
Ref<Texture2D> object_texture = _get_edited_object_texture();
const Ref<Texture2D> object_texture = _get_edited_object_texture();
if (object_texture.is_null()) {
return;
}
@ -860,14 +860,6 @@ void TextureRegionEditor::_node_removed(Node *p_node) {
}
void TextureRegionEditor::_clear_edited_object() {
node_sprite_2d = nullptr;
node_sprite_3d = nullptr;
node_ninepatch = nullptr;
res_stylebox = Ref<StyleBoxTexture>();
res_atlas_texture = Ref<AtlasTexture>();
}
void TextureRegionEditor::edit(Object *p_obj) {
if (node_sprite_2d) {
node_sprite_2d->disconnect("texture_changed", callable_mp(this, &TextureRegionEditor::_texture_changed));
}
@ -884,6 +876,14 @@ void TextureRegionEditor::edit(Object *p_obj) {
res_atlas_texture->disconnect_changed(callable_mp(this, &TextureRegionEditor::_texture_changed));
}
node_sprite_2d = nullptr;
node_sprite_3d = nullptr;
node_ninepatch = nullptr;
res_stylebox = Ref<StyleBoxTexture>();
res_atlas_texture = Ref<AtlasTexture>();
}
void TextureRegionEditor::edit(Object *p_obj) {
_clear_edited_object();
if (p_obj) {
@ -950,8 +950,9 @@ Rect2 TextureRegionEditor::_get_edited_object_region() const {
region = res_atlas_texture->get_region();
}
if (region == Rect2()) {
region = Rect2(Vector2(), _get_edited_object_texture()->get_size());
const Ref<Texture2D> object_texture = _get_edited_object_texture();
if (region == Rect2() && object_texture.is_valid()) {
region = Rect2(Vector2(), object_texture->get_size());
}
return region;
@ -965,7 +966,7 @@ void TextureRegionEditor::_texture_changed() {
}
void TextureRegionEditor::_edit_region() {
Ref<Texture2D> object_texture = _get_edited_object_texture();
const Ref<Texture2D> object_texture = _get_edited_object_texture();
if (object_texture.is_null()) {
_zoom_reset();
hscroll->hide();