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.
This commit is contained in:
Brecht Van Lommel 2020-10-02 19:30:19 +02:00
parent 350ed861f1
commit 38cdc7bcc1
1 changed files with 5 additions and 3 deletions

View File

@ -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);