Browse Source

Merge pull request #52466 from tcoxon/fix_43733_4.0

Prevent shaders from generating code before the constructor finishes.
Rémi Verschelde 4 years ago
parent
commit
91960b7b81

+ 2 - 1
scene/resources/canvas_item_material.cpp

@@ -161,7 +161,7 @@ void CanvasItemMaterial::flush_changes() {
 void CanvasItemMaterial::_queue_shader_change() {
 void CanvasItemMaterial::_queue_shader_change() {
 	MutexLock lock(material_mutex);
 	MutexLock lock(material_mutex);
 
 
-	if (!element.in_list()) {
+	if (is_initialized && !element.in_list()) {
 		dirty_materials->add(&element);
 		dirty_materials->add(&element);
 	}
 	}
 }
 }
@@ -287,6 +287,7 @@ CanvasItemMaterial::CanvasItemMaterial() :
 	set_particles_anim_loop(false);
 	set_particles_anim_loop(false);
 
 
 	current_key.invalid_key = 1;
 	current_key.invalid_key = 1;
+	is_initialized = true;
 	_queue_shader_change();
 	_queue_shader_change();
 }
 }
 
 

+ 1 - 0
scene/resources/canvas_item_material.h

@@ -102,6 +102,7 @@ private:
 	_FORCE_INLINE_ void _queue_shader_change();
 	_FORCE_INLINE_ void _queue_shader_change();
 	_FORCE_INLINE_ bool _is_shader_dirty() const;
 	_FORCE_INLINE_ bool _is_shader_dirty() const;
 
 
+	bool is_initialized = false;
 	BlendMode blend_mode = BLEND_MODE_MIX;
 	BlendMode blend_mode = BLEND_MODE_MIX;
 	LightMode light_mode = LIGHT_MODE_NORMAL;
 	LightMode light_mode = LIGHT_MODE_NORMAL;
 	bool particles_animation = false;
 	bool particles_animation = false;

+ 2 - 1
scene/resources/material.cpp

@@ -1301,7 +1301,7 @@ void BaseMaterial3D::flush_changes() {
 void BaseMaterial3D::_queue_shader_change() {
 void BaseMaterial3D::_queue_shader_change() {
 	MutexLock lock(material_mutex);
 	MutexLock lock(material_mutex);
 
 
-	if (!element.in_list()) {
+	if (is_initialized && !element.in_list()) {
 		dirty_materials->add(&element);
 		dirty_materials->add(&element);
 	}
 	}
 }
 }
@@ -2777,6 +2777,7 @@ BaseMaterial3D::BaseMaterial3D(bool p_orm) :
 
 
 	flags[FLAG_USE_TEXTURE_REPEAT] = true;
 	flags[FLAG_USE_TEXTURE_REPEAT] = true;
 
 
+	is_initialized = true;
 	_queue_shader_change();
 	_queue_shader_change();
 }
 }
 
 

+ 1 - 0
scene/resources/material.h

@@ -440,6 +440,7 @@ private:
 	_FORCE_INLINE_ void _queue_shader_change();
 	_FORCE_INLINE_ void _queue_shader_change();
 	_FORCE_INLINE_ bool _is_shader_dirty() const;
 	_FORCE_INLINE_ bool _is_shader_dirty() const;
 
 
+	bool is_initialized = false;
 	bool orm;
 	bool orm;
 
 
 	Color albedo;
 	Color albedo;

+ 2 - 1
scene/resources/particles_material.cpp

@@ -741,7 +741,7 @@ void ParticlesMaterial::flush_changes() {
 void ParticlesMaterial::_queue_shader_change() {
 void ParticlesMaterial::_queue_shader_change() {
 	MutexLock lock(material_mutex);
 	MutexLock lock(material_mutex);
 
 
-	if (!element.in_list()) {
+	if (is_initialized && !element.in_list()) {
 		dirty_materials->add(&element);
 		dirty_materials->add(&element);
 	}
 	}
 }
 }
@@ -1533,6 +1533,7 @@ ParticlesMaterial::ParticlesMaterial() :
 
 
 	current_key.invalid_key = 1;
 	current_key.invalid_key = 1;
 
 
+	is_initialized = true;
 	_queue_shader_change();
 	_queue_shader_change();
 }
 }
 
 

+ 1 - 0
scene/resources/particles_material.h

@@ -226,6 +226,7 @@ private:
 	_FORCE_INLINE_ void _queue_shader_change();
 	_FORCE_INLINE_ void _queue_shader_change();
 	_FORCE_INLINE_ bool _is_shader_dirty() const;
 	_FORCE_INLINE_ bool _is_shader_dirty() const;
 
 
+	bool is_initialized = false;
 	Vector3 direction;
 	Vector3 direction;
 	float spread;
 	float spread;
 	float flatness;
 	float flatness;