Fix: Crash in sculpt mode with shared normals caches #4

Closed
Hans Goudey wants to merge 3 commits from fix-pbvh-normals-crash into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
2 changed files with 4 additions and 3 deletions
Showing only changes of commit 5e859a085e - Show all commits

View File

@ -1316,7 +1316,7 @@ static void pbvh_faces_update_normals(PBVH *pbvh, Span<PBVHNode *> nodes, Mesh &
VectorSet<int> verts_to_update;
threading::parallel_invoke(
[&]() {
mesh.runtime->face_normals_cache.ensure([&](Vector<float3> &r_data) {
mesh.runtime->face_normals_cache.update([&](Vector<float3> &r_data) {
threading::parallel_for(faces_to_update.index_range(), 512, [&](const IndexRange range) {
for (const int i : faces_to_update.as_span().slice(range)) {
r_data[i] = mesh::face_normal_calc(positions, corner_verts.slice(faces[i]));
@ -1340,7 +1340,7 @@ static void pbvh_faces_update_normals(PBVH *pbvh, Span<PBVHNode *> nodes, Mesh &
});
const Span<float3> face_normals = mesh.face_normals();
mesh.runtime->vert_normals_cache.ensure([&](Vector<float3> &r_data) {
mesh.runtime->vert_normals_cache.update([&](Vector<float3> &r_data) {
threading::parallel_for(verts_to_update.index_range(), 1024, [&](const IndexRange range) {
for (const int vert : verts_to_update.as_span().slice(range)) {
float3 normal(0.0f);

View File

@ -30,7 +30,8 @@ template<typename T> class SharedCache {
struct CacheData {
CacheMutex mutex;
T data;
CacheData(T data) : data(std::move(data)) {}
CacheData() = default;
CacheData(const T &data) : data(data) {}
};
std::shared_ptr<CacheData> cache_;