Explorar o código

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)
Colin O'Rourke hai 1 mes
pai
achega
0f760c7c97

+ 1 - 0
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<Resource> 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);

+ 8 - 0
editor/scene/material_editor_plugin.cpp

@@ -456,6 +456,7 @@ bool StandardMaterial3DConversionPlugin::handles(const Ref<Resource> &p_resource
 Ref<Resource> StandardMaterial3DConversionPlugin::convert(const Ref<Resource> &p_resource) const {
 	Ref<StandardMaterial3D> mat = p_resource;
 	ERR_FAIL_COND_V(mat.is_null(), Ref<Resource>());
+	ERR_FAIL_COND_V(!mat->_is_initialized(), Ref<Resource>());
 
 	Ref<ShaderMaterial> smat;
 	smat.instantiate();
@@ -502,6 +503,7 @@ bool ORMMaterial3DConversionPlugin::handles(const Ref<Resource> &p_resource) con
 Ref<Resource> ORMMaterial3DConversionPlugin::convert(const Ref<Resource> &p_resource) const {
 	Ref<ORMMaterial3D> mat = p_resource;
 	ERR_FAIL_COND_V(mat.is_null(), Ref<Resource>());
+	ERR_FAIL_COND_V(!mat->_is_initialized(), Ref<Resource>());
 
 	Ref<ShaderMaterial> smat;
 	smat.instantiate();
@@ -548,6 +550,7 @@ bool ParticleProcessMaterialConversionPlugin::handles(const Ref<Resource> &p_res
 Ref<Resource> ParticleProcessMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
 	Ref<ParticleProcessMaterial> mat = p_resource;
 	ERR_FAIL_COND_V(mat.is_null(), Ref<Resource>());
+	ERR_FAIL_COND_V(!mat->_is_initialized(), Ref<Resource>());
 
 	Ref<ShaderMaterial> smat;
 	smat.instantiate();
@@ -587,6 +590,7 @@ bool CanvasItemMaterialConversionPlugin::handles(const Ref<Resource> &p_resource
 Ref<Resource> CanvasItemMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
 	Ref<CanvasItemMaterial> mat = p_resource;
 	ERR_FAIL_COND_V(mat.is_null(), Ref<Resource>());
+	ERR_FAIL_COND_V(!mat->_is_initialized(), Ref<Resource>());
 
 	Ref<ShaderMaterial> smat;
 	smat.instantiate();
@@ -626,6 +630,7 @@ bool ProceduralSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resou
 Ref<Resource> ProceduralSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
 	Ref<ProceduralSkyMaterial> mat = p_resource;
 	ERR_FAIL_COND_V(mat.is_null(), Ref<Resource>());
+	ERR_FAIL_COND_V(!mat->_is_initialized(), Ref<Resource>());
 
 	Ref<ShaderMaterial> smat;
 	smat.instantiate();
@@ -665,6 +670,7 @@ bool PanoramaSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resourc
 Ref<Resource> PanoramaSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
 	Ref<PanoramaSkyMaterial> mat = p_resource;
 	ERR_FAIL_COND_V(mat.is_null(), Ref<Resource>());
+	ERR_FAIL_COND_V(!mat->_is_initialized(), Ref<Resource>());
 
 	Ref<ShaderMaterial> smat;
 	smat.instantiate();
@@ -704,6 +710,7 @@ bool PhysicalSkyMaterialConversionPlugin::handles(const Ref<Resource> &p_resourc
 Ref<Resource> PhysicalSkyMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
 	Ref<PhysicalSkyMaterial> mat = p_resource;
 	ERR_FAIL_COND_V(mat.is_null(), Ref<Resource>());
+	ERR_FAIL_COND_V(!mat->_is_initialized(), Ref<Resource>());
 
 	Ref<ShaderMaterial> smat;
 	smat.instantiate();
@@ -743,6 +750,7 @@ bool FogMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const
 Ref<Resource> FogMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) const {
 	Ref<FogMaterial> mat = p_resource;
 	ERR_FAIL_COND_V(mat.is_null(), Ref<Resource>());
+	ERR_FAIL_COND_V(!mat->_is_initialized(), Ref<Resource>());
 
 	Ref<ShaderMaterial> smat;
 	smat.instantiate();

+ 3 - 1
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<Material> &p_pass);
 	Ref<Material> get_next_pass() const;