From dbe757102c6503eb564c9edc699c89afe63b91cd Mon Sep 17 00:00:00 2001 From: Tom Coxon Date: Tue, 7 Sep 2021 16:39:37 +0100 Subject: 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. --- scene/resources/canvas_item_material.h | 1 + 1 file changed, 1 insertion(+) (limited to 'scene/resources/canvas_item_material.h') diff --git a/scene/resources/canvas_item_material.h b/scene/resources/canvas_item_material.h index 0a813e0ae5..37cd4de136 100644 --- a/scene/resources/canvas_item_material.h +++ b/scene/resources/canvas_item_material.h @@ -102,6 +102,7 @@ private: _FORCE_INLINE_ void _queue_shader_change(); _FORCE_INLINE_ bool _is_shader_dirty() const; + bool is_initialized = false; BlendMode blend_mode = BLEND_MODE_MIX; LightMode light_mode = LIGHT_MODE_NORMAL; bool particles_animation = false; -- cgit v1.2.3