summaryrefslogtreecommitdiff
path: root/scene/resources/particles_material.cpp
diff options
context:
space:
mode:
authorTom Coxon <tom.c.coxon@gmail.com>2021-09-07 16:39:37 +0100
committerTom Coxon <tom.c.coxon@gmail.com>2021-09-21 11:51:39 +0100
commitdbe757102c6503eb564c9edc699c89afe63b91cd (patch)
tree6d65b969a9f7c2e6b67f73bbc3874622be9f065e /scene/resources/particles_material.cpp
parent93aa158b5e1b3b11c3482834504e791c3898baf0 (diff)
Prevent shaders from generating code before the constructor finishes.
Fixes #43733: "creating SpatialMaterial in a separate thread creates invalid shaders (temporarily)." The bug occurred because various setters called in materials' constructors add materials to queues that are processed on the main thread. This means that when the materials are created in another thread, they can be processed on the main thread before the constructor has finished. The fix adds a flag to affected materials that prevents them from being added to the queue until their constructors have finished initialising all the members.
Diffstat (limited to 'scene/resources/particles_material.cpp')
-rw-r--r--scene/resources/particles_material.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp
index 0495a9e92c..d9ec0bfd69 100644
--- a/scene/resources/particles_material.cpp
+++ b/scene/resources/particles_material.cpp
@@ -741,7 +741,7 @@ void ParticlesMaterial::flush_changes() {
void ParticlesMaterial::_queue_shader_change() {
MutexLock lock(material_mutex);
- if (!element.in_list()) {
+ if (is_initialized && !element.in_list()) {
dirty_materials->add(&element);
}
}
@@ -1533,6 +1533,7 @@ ParticlesMaterial::ParticlesMaterial() :
current_key.invalid_key = 1;
+ is_initialized = true;
_queue_shader_change();
}