You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-08 12:40:44 +00:00
Prevent crash and error spam related to Sprite2D with a region
This commit is contained in:
@@ -127,59 +127,57 @@ void Sprite2DEditor::_menu_option(int p_option) {
|
|||||||
debug_uv_dialog->set_ok_button_text(TTR("Create MeshInstance2D"));
|
debug_uv_dialog->set_ok_button_text(TTR("Create MeshInstance2D"));
|
||||||
debug_uv_dialog->set_title(TTR("MeshInstance2D Preview"));
|
debug_uv_dialog->set_title(TTR("MeshInstance2D Preview"));
|
||||||
|
|
||||||
_update_mesh_data();
|
_popup_debug_uv_dialog();
|
||||||
debug_uv_dialog->popup_centered();
|
|
||||||
debug_uv->queue_redraw();
|
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case MENU_OPTION_CONVERT_TO_POLYGON_2D: {
|
case MENU_OPTION_CONVERT_TO_POLYGON_2D: {
|
||||||
debug_uv_dialog->set_ok_button_text(TTR("Create Polygon2D"));
|
debug_uv_dialog->set_ok_button_text(TTR("Create Polygon2D"));
|
||||||
debug_uv_dialog->set_title(TTR("Polygon2D Preview"));
|
debug_uv_dialog->set_title(TTR("Polygon2D Preview"));
|
||||||
|
|
||||||
_update_mesh_data();
|
_popup_debug_uv_dialog();
|
||||||
debug_uv_dialog->popup_centered();
|
|
||||||
debug_uv->queue_redraw();
|
|
||||||
} break;
|
} break;
|
||||||
case MENU_OPTION_CREATE_COLLISION_POLY_2D: {
|
case MENU_OPTION_CREATE_COLLISION_POLY_2D: {
|
||||||
debug_uv_dialog->set_ok_button_text(TTR("Create CollisionPolygon2D"));
|
debug_uv_dialog->set_ok_button_text(TTR("Create CollisionPolygon2D"));
|
||||||
debug_uv_dialog->set_title(TTR("CollisionPolygon2D Preview"));
|
debug_uv_dialog->set_title(TTR("CollisionPolygon2D Preview"));
|
||||||
|
|
||||||
_update_mesh_data();
|
_popup_debug_uv_dialog();
|
||||||
debug_uv_dialog->popup_centered();
|
|
||||||
debug_uv->queue_redraw();
|
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case MENU_OPTION_CREATE_LIGHT_OCCLUDER_2D: {
|
case MENU_OPTION_CREATE_LIGHT_OCCLUDER_2D: {
|
||||||
debug_uv_dialog->set_ok_button_text(TTR("Create LightOccluder2D"));
|
debug_uv_dialog->set_ok_button_text(TTR("Create LightOccluder2D"));
|
||||||
debug_uv_dialog->set_title(TTR("LightOccluder2D Preview"));
|
debug_uv_dialog->set_title(TTR("LightOccluder2D Preview"));
|
||||||
|
|
||||||
_update_mesh_data();
|
_popup_debug_uv_dialog();
|
||||||
debug_uv_dialog->popup_centered();
|
|
||||||
debug_uv->queue_redraw();
|
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite2DEditor::_update_mesh_data() {
|
void Sprite2DEditor::_popup_debug_uv_dialog() {
|
||||||
|
String error_message;
|
||||||
if (node->get_owner() != get_tree()->get_edited_scene_root()) {
|
if (node->get_owner() != get_tree()->get_edited_scene_root()) {
|
||||||
err_dialog->set_text(TTR("Can't convert a Sprite2D from a foreign scene."));
|
error_message = TTR("Can't convert a sprite from a foreign scene.");
|
||||||
err_dialog->popup_centered();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Texture2D> texture = node->get_texture();
|
Ref<Texture2D> texture = node->get_texture();
|
||||||
if (texture.is_null()) {
|
if (texture.is_null()) {
|
||||||
err_dialog->set_text(TTR("Sprite2D is empty!"));
|
error_message = TTR("Can't convert an empty sprite to mesh.");
|
||||||
err_dialog->popup_centered();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node->get_hframes() > 1 || node->get_vframes() > 1) {
|
if (node->get_hframes() > 1 || node->get_vframes() > 1) {
|
||||||
err_dialog->set_text(TTR("Can't convert a sprite using animation frames to mesh."));
|
error_message = TTR("Can't convert a sprite using animation frames to mesh.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!error_message.is_empty()) {
|
||||||
|
err_dialog->set_text(error_message);
|
||||||
err_dialog->popup_centered();
|
err_dialog->popup_centered();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_update_mesh_data();
|
||||||
|
debug_uv_dialog->popup_centered();
|
||||||
|
debug_uv->queue_redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Sprite2DEditor::_update_mesh_data() {
|
||||||
|
ERR_FAIL_NULL(node);
|
||||||
|
Ref<Texture2D> texture = node->get_texture();
|
||||||
|
ERR_FAIL_COND(texture.is_null());
|
||||||
Ref<Image> image = texture->get_image();
|
Ref<Image> image = texture->get_image();
|
||||||
ERR_FAIL_COND(image.is_null());
|
ERR_FAIL_COND(image.is_null());
|
||||||
|
|
||||||
@@ -187,12 +185,9 @@ void Sprite2DEditor::_update_mesh_data() {
|
|||||||
image->decompress();
|
image->decompress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Add support for Sprite2D's region.
|
||||||
Rect2 rect;
|
Rect2 rect;
|
||||||
if (node->is_region_enabled()) {
|
|
||||||
rect = node->get_region_rect();
|
|
||||||
} else {
|
|
||||||
rect.size = image->get_size();
|
rect.size = image->get_size();
|
||||||
}
|
|
||||||
|
|
||||||
Ref<BitMap> bm;
|
Ref<BitMap> bm;
|
||||||
bm.instantiate();
|
bm.instantiate();
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ class Sprite2DEditor : public Control {
|
|||||||
friend class Sprite2DEditorPlugin;
|
friend class Sprite2DEditorPlugin;
|
||||||
|
|
||||||
void _debug_uv_draw();
|
void _debug_uv_draw();
|
||||||
|
void _popup_debug_uv_dialog();
|
||||||
void _update_mesh_data();
|
void _update_mesh_data();
|
||||||
|
|
||||||
void _create_node();
|
void _create_node();
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ Transform2D TextureRegionEditor::_get_offset_transform() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextureRegionEditor::_texture_preview_draw() {
|
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()) {
|
if (object_texture.is_null()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -68,7 +68,7 @@ void TextureRegionEditor::_texture_preview_draw() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextureRegionEditor::_texture_overlay_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()) {
|
if (object_texture.is_null()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -746,7 +746,7 @@ void TextureRegionEditor::_update_autoslice() {
|
|||||||
autoslice_is_dirty = false;
|
autoslice_is_dirty = false;
|
||||||
autoslice_cache.clear();
|
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()) {
|
if (object_texture.is_null()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -860,14 +860,6 @@ void TextureRegionEditor::_node_removed(Node *p_node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextureRegionEditor::_clear_edited_object() {
|
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) {
|
if (node_sprite_2d) {
|
||||||
node_sprite_2d->disconnect("texture_changed", callable_mp(this, &TextureRegionEditor::_texture_changed));
|
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));
|
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();
|
_clear_edited_object();
|
||||||
|
|
||||||
if (p_obj) {
|
if (p_obj) {
|
||||||
@@ -950,8 +950,9 @@ Rect2 TextureRegionEditor::_get_edited_object_region() const {
|
|||||||
region = res_atlas_texture->get_region();
|
region = res_atlas_texture->get_region();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (region == Rect2()) {
|
const Ref<Texture2D> object_texture = _get_edited_object_texture();
|
||||||
region = Rect2(Vector2(), _get_edited_object_texture()->get_size());
|
if (region == Rect2() && object_texture.is_valid()) {
|
||||||
|
region = Rect2(Vector2(), object_texture->get_size());
|
||||||
}
|
}
|
||||||
|
|
||||||
return region;
|
return region;
|
||||||
@@ -965,7 +966,7 @@ void TextureRegionEditor::_texture_changed() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextureRegionEditor::_edit_region() {
|
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()) {
|
if (object_texture.is_null()) {
|
||||||
_zoom_reset();
|
_zoom_reset();
|
||||||
hscroll->hide();
|
hscroll->hide();
|
||||||
|
|||||||
Reference in New Issue
Block a user