From 05fd79af7c706c8bda112f4ec3eb95977a96bc9d Mon Sep 17 00:00:00 2001 From: Colin O'Rourke Date: Thu, 31 Jul 2025 01:33:01 -0700 Subject: [PATCH] Material Conversion Error Handling Material Conversion Plugins now ERR_FAIL if called on an unitialized material. FileSystemDock no longer crashes if Conversion Plugin fails and returns a null ref. --- editor/docks/filesystem_dock.cpp | 1 + editor/scene/material_editor_plugin.cpp | 8 ++++++++ scene/resources/material.h | 4 +++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/editor/docks/filesystem_dock.cpp b/editor/docks/filesystem_dock.cpp index 1a663d069aa..529786c5e70 100644 --- a/editor/docks/filesystem_dock.cpp +++ b/editor/docks/filesystem_dock.cpp @@ -1900,6 +1900,7 @@ void FileSystemDock::_convert_dialog_action() { for (const String &target : cached_valid_conversion_targets) { if (conversion_id == selected_conversion_id && conversion->converts_to() == target) { Ref converted_res = conversion->convert(res); + ERR_FAIL_COND(converted_res.is_null()); ERR_FAIL_COND(res.is_null()); converted_resources.push_back(converted_res); resources_to_erase_history_for.insert(res); diff --git a/editor/scene/material_editor_plugin.cpp b/editor/scene/material_editor_plugin.cpp index 9965ed65aca..f4b2281e154 100644 --- a/editor/scene/material_editor_plugin.cpp +++ b/editor/scene/material_editor_plugin.cpp @@ -456,6 +456,7 @@ bool StandardMaterial3DConversionPlugin::handles(const Ref &p_resource Ref StandardMaterial3DConversionPlugin::convert(const Ref &p_resource) const { Ref mat = p_resource; ERR_FAIL_COND_V(mat.is_null(), Ref()); + ERR_FAIL_COND_V(!mat->_is_initialized(), Ref()); Ref smat; smat.instantiate(); @@ -502,6 +503,7 @@ bool ORMMaterial3DConversionPlugin::handles(const Ref &p_resource) con Ref ORMMaterial3DConversionPlugin::convert(const Ref &p_resource) const { Ref mat = p_resource; ERR_FAIL_COND_V(mat.is_null(), Ref()); + ERR_FAIL_COND_V(!mat->_is_initialized(), Ref()); Ref smat; smat.instantiate(); @@ -548,6 +550,7 @@ bool ParticleProcessMaterialConversionPlugin::handles(const Ref &p_res Ref ParticleProcessMaterialConversionPlugin::convert(const Ref &p_resource) const { Ref mat = p_resource; ERR_FAIL_COND_V(mat.is_null(), Ref()); + ERR_FAIL_COND_V(!mat->_is_initialized(), Ref()); Ref smat; smat.instantiate(); @@ -587,6 +590,7 @@ bool CanvasItemMaterialConversionPlugin::handles(const Ref &p_resource Ref CanvasItemMaterialConversionPlugin::convert(const Ref &p_resource) const { Ref mat = p_resource; ERR_FAIL_COND_V(mat.is_null(), Ref()); + ERR_FAIL_COND_V(!mat->_is_initialized(), Ref()); Ref smat; smat.instantiate(); @@ -626,6 +630,7 @@ bool ProceduralSkyMaterialConversionPlugin::handles(const Ref &p_resou Ref ProceduralSkyMaterialConversionPlugin::convert(const Ref &p_resource) const { Ref mat = p_resource; ERR_FAIL_COND_V(mat.is_null(), Ref()); + ERR_FAIL_COND_V(!mat->_is_initialized(), Ref()); Ref smat; smat.instantiate(); @@ -665,6 +670,7 @@ bool PanoramaSkyMaterialConversionPlugin::handles(const Ref &p_resourc Ref PanoramaSkyMaterialConversionPlugin::convert(const Ref &p_resource) const { Ref mat = p_resource; ERR_FAIL_COND_V(mat.is_null(), Ref()); + ERR_FAIL_COND_V(!mat->_is_initialized(), Ref()); Ref smat; smat.instantiate(); @@ -704,6 +710,7 @@ bool PhysicalSkyMaterialConversionPlugin::handles(const Ref &p_resourc Ref PhysicalSkyMaterialConversionPlugin::convert(const Ref &p_resource) const { Ref mat = p_resource; ERR_FAIL_COND_V(mat.is_null(), Ref()); + ERR_FAIL_COND_V(!mat->_is_initialized(), Ref()); Ref smat; smat.instantiate(); @@ -743,6 +750,7 @@ bool FogMaterialConversionPlugin::handles(const Ref &p_resource) const Ref FogMaterialConversionPlugin::convert(const Ref &p_resource) const { Ref mat = p_resource; ERR_FAIL_COND_V(mat.is_null(), Ref()); + ERR_FAIL_COND_V(!mat->_is_initialized(), Ref()); Ref smat; smat.instantiate(); diff --git a/scene/resources/material.h b/scene/resources/material.h index 081a2356fbd..0e99015c41c 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -64,7 +64,6 @@ protected: void _mark_ready(); void _mark_initialized(const Callable &p_add_to_dirty_list, const Callable &p_update_shader); - bool _is_initialized() { return init_state == INIT_STATE_READY; } GDVIRTUAL0RC_REQUIRED(RID, _get_shader_rid) GDVIRTUAL0RC_REQUIRED(Shader::Mode, _get_shader_mode) @@ -75,6 +74,9 @@ public: RENDER_PRIORITY_MAX = RS::MATERIAL_RENDER_PRIORITY_MAX, RENDER_PRIORITY_MIN = RS::MATERIAL_RENDER_PRIORITY_MIN, }; + + bool _is_initialized() { return init_state == INIT_STATE_READY; } + void set_next_pass(const Ref &p_pass); Ref get_next_pass() const;