Fix: Crash and or assert in mesh index buffer creation

The mapping was read multiple times from the `map` structure in that time the `map` value could have changed (set to -1). To stop this, the mapping is read once and set to -1 earlier to reduce the possibility to other threads performing the operation and changing the mapping value.

Pull Request: https://projects.blender.org/blender/blender/pulls/123056
This commit is contained in:
William Leeson
2024-06-11 16:13:27 +02:00
committed by William Leeson
parent e175259f44
commit 81d5af15a6
2 changed files with 8 additions and 6 deletions

View File

@@ -137,8 +137,8 @@ static void extract_lines_mesh(const MeshRenderData &mr,
for (const int corner : face) {
const int edge = corner_edges[corner];
if (!used[edge]) {
data[edge] = edge_from_corners(face, corner);
used[edge] = true;
data[edge] = edge_from_corners(face, corner);
}
}
}
@@ -156,9 +156,10 @@ static void extract_lines_mesh(const MeshRenderData &mr,
const IndexRange face = faces[face_index];
for (const int corner : face) {
const int edge = corner_edges[corner];
if (map[edge] != -1) {
data[map[edge]] = edge_from_corners(face, corner);
const int vbo_index = map[edge];
if (vbo_index != -1) {
map[edge] = -1;
data[vbo_index] = edge_from_corners(face, corner);
}
}
}

View File

@@ -82,8 +82,8 @@ static void extract_points_mesh(const MeshRenderData &mr, gpu::IndexBuf &points)
Array<bool> used(mr.verts_num, false);
process_ibo_verts_mesh(mr, [&](const int ibo_index, const int vert) {
if (!used[vert]) {
data[vert] = ibo_index;
used[vert] = true;
data[vert] = ibo_index;
}
});
}
@@ -92,9 +92,10 @@ static void extract_points_mesh(const MeshRenderData &mr, gpu::IndexBuf &points)
Array<int> map(mr.verts_num, -1);
index_mask::build_reverse_map(visible_verts, map.as_mutable_span());
process_ibo_verts_mesh(mr, [&](const int ibo_index, const int vert) {
if (map[vert] != -1) {
data[map[vert]] = ibo_index;
const int index = map[vert];
if (index != -1) {
map[vert] = -1;
data[index] = ibo_index;
}
});
}