Cycles: Guard memcpy to potentially re-allocating memory with lock
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 14 Aug 2017 12:55:47 +0000 (14:55 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 14 Aug 2017 12:55:47 +0000 (14:55 +0200)
Basically, make re-alloc and memcpy from the same lock, otherwise one
thread might be re-allocating thread while another one is trying to
copy data there.

Reported by Mohamed Sakr in IRC, thanks!

intern/cycles/bvh/bvh_build.cpp

index 933e98fea0142a0add2a4d49beabf02ed1c77c17..eb1d89729fbfe30a26dba7711067e458f73d86e2 100644 (file)
@@ -1040,7 +1040,6 @@ BVHNode* BVHBuild::create_leaf_node(const BVHRange& range,
                 */
                start_index = spatial_free_index;
                spatial_free_index += range.size();
-
                /* Extend an array when needed. */
                const size_t range_end = start_index + range.size();
                if(prim_type.size() < range_end) {
@@ -1066,8 +1065,6 @@ BVHNode* BVHBuild::create_leaf_node(const BVHRange& range,
                                prim_time.resize(range_end);
                        }
                }
-               spatial_spin_lock.unlock();
-
                /* Perform actual data copy. */
                if(new_leaf_data_size > 0) {
                        memcpy(&prim_type[start_index], &local_prim_type[0], new_leaf_data_size);
@@ -1077,6 +1074,7 @@ BVHNode* BVHBuild::create_leaf_node(const BVHRange& range,
                                memcpy(&prim_time[start_index], &local_prim_time[0], sizeof(float2)*num_new_leaf_data);
                        }
                }
+               spatial_spin_lock.unlock();
        }
        else {
                /* For the regular BVH builder we simply copy new data starting at the