From 0af3765f779e376bb774c61d6144cc0b225b73a3 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. (cherry picked from commit 05fd79af7c706c8bda112f4ec3eb95977a96bc9d) --- editor/filesystem_dock.cpp | 1 + editor/plugins/material_editor_plugin.cpp | 8 ++++++++ scene/resources/material.h | 4 +++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 4fafdefbb59..e60ab3841f1 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -1880,6 +1880,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/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp index b17e9927ab8..bab0f30f42d 100644 --- a/editor/plugins/material_editor_plugin.cpp +++ b/editor/plugins/material_editor_plugin.cpp @@ -450,6 +450,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(); @@ -496,6 +497,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(); @@ -542,6 +544,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(); @@ -581,6 +584,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(); @@ -620,6 +624,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(); @@ -659,6 +664,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(); @@ -698,6 +704,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(); @@ -737,6 +744,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 36d325bd33f..13b70b7e3a4 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -65,7 +65,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) @@ -76,6 +75,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;