Fix #112351: Sculpt implicit sharing thread safety crash #112690
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#112690
Loading…
Reference in New Issue
No description provided.
Delete Branch "HooglyBoogly/blender:sculpt-implicit-sharing-crash"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Currently the iteration over a PBVH node's vertices retrieves mutable
access to the mask custom data layer. This isn't threadsafe, but it is
done in the multithreaded loops over all nodes.
In general, we need to be more careful and conservative about storage
of non-const pointers to mesh data. Ideally we would only have one
mutable reference to a resource at a time. And we should avoid doing
work like looking up custom data layers more than we need to.
To that end, make the pointer to the custom data layer used everywhere
const, and retrieve mutable access before parallel node iteration with
a specific function, and write to the mask data with that in mind.
This pushes us in the direction of sharing less code per PBVH type.
In my opinion that's a good thing, because we can actually optimize for
each type. For example,
SCULPT_mask_write_array
gives a picture ofhow each of these hot loops could become much simpler.
On a bigger scale the change sounds good, and did not spot obvious mistakes. There are some inlined comments though which would be nice to iterate over.
@ -502,3 +504,3 @@
int totvert;
const int *vert_indices;
float *vmask;
const float *vmask;
Intuitively this should no longer be a pointer, but a single float. It used to be a pointer to allow an easy write access which is now done by
SCULPT_mask_vert_set
.Totally agree! But do you mind if I do that in a separate commit after this? It would make the diff much bigger I think.
Separate commit sounds perfectly fine.
@ -2718,3 +2718,3 @@
for (int i = 0; i < data->totlayer; i++) {
if (data->layers[i].type == type) {
BLI_assert(uint(n) < uint(layer_num));
BLI_assert(n < layer_num);
This does not seem to be related to the problem which the patch description is solving.
Right, sorry! It was required to make the file from the bug report load without an assert. But I'll remove it now.
@ -74,3 +74,3 @@
{0}};
static void mask_flood_fill_set_elem(float *elem, PaintMaskFloodMode mode, float value)
static float mask_flood_fill_set_elem(const float elem, PaintMaskFloodMode mode, float value)
I do not think it is valid to call it "set_elem" anymore. It is more of "get_new_value_for_elem" type of operation.
@ -122,1 +121,3 @@
if (prevmask != *vi.mask) {
const float new_mask = mask_flood_fill_set_elem(prevmask, mode, value);
if (prevmask != new_mask) {
SCULPT_mask_vert_set(BKE_pbvh_type(ob->sculpt->pbvh), mask_write, new_mask, vi);
The first
BKE_pbvh_type(ob->sculpt->pbvh)
argument seems to be repeated for every function. Did you consider passing the session/pbvh instead to shorten the invocation line?I don't have a strong opinion, but I chose this way so it was clear that the function didn't depend on any other part of the
PBVH
besides the type. Otherwise it felt a bit more like a black box.Initially I wanted to not have the
SCULPT_mask_vert_set
function at all for the same reason, but that made a bit too much code duplication.Hrm, you do have a good point. Well, lets leave it as-is then :)
@ -1205,3 +1200,1 @@
BKE_pbvh_vertex_iter_end;
BKE_pbvh_node_mark_redraw(node);
}
SCULPT_mask_write_array(ss, nodes, {expand_cache->original_mask, SCULPT_vertex_count_get(ss)});
To me this can/should be split into a separate change, for the ease of bisect. Unless there is some dependency with the rest of the changes in this patch.
Thanks for the updates.
Only did code review, which seems fine. Please make sure you've tested code on a functional level before landing :)