diff options
author | Brecht Van Lommel <brecht@blender.org> | 2020-10-02 20:30:19 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2020-10-02 20:42:20 +0300 |
commit | 38cdc7bcc1f2ac7e89578be079e4be0b049a4036 (patch) | |
tree | ec1c03a178844f105e0a6bf3ba66ce97bf2207b3 /source/blender/blenkernel/intern | |
parent | 350ed861f149142784fc184086e92664b72a10ef (diff) |
Fix non-thread safe code in view layer object hash
Found as part of D8324, multithreaded Cycles object sync, where it caused
a crash on concurrent access to object holdout state.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/layer.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index 1d47fb002e6..4ed8a796d5d 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -358,14 +358,16 @@ static void view_layer_bases_hash_create(ViewLayer *view_layer) BLI_mutex_lock(&hash_lock); if (view_layer->object_bases_hash == NULL) { - view_layer->object_bases_hash = BLI_ghash_new( - BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__); + GHash *hash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__); LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) { if (base->object) { - BLI_ghash_insert(view_layer->object_bases_hash, base->object, base); + BLI_ghash_insert(hash, base->object, base); } } + + /* Assign pointer only after hash is complete. */ + view_layer->object_bases_hash = hash; } BLI_mutex_unlock(&hash_lock); |