Fix #125157: Sculpt multires crashes on box mask and duplicated stroke #125268

Merged
Sean Kim merged 7 commits from Sean-Kim/blender:fix-125157 into main 2024-07-23 22:56:45 +02:00
Member

Introduced in d527e3a6bd.

The change to update PBVH normals before destroying the PBVH to fix
shading on duplicate meshes issues had the unfortunate side effect of
causing crashes for multires due to a race condition. This commit
simply avoids performing this flushing for multires to allow for
further iteration in the future instead of reverting the offending
commit entirely.

Introduced in d527e3a6bd787c2f58837c6f93ccd7d8b466c779. The change to update PBVH normals before destroying the PBVH to fix shading on duplicate meshes issues had the unfortunate side effect of causing crashes for multires due to a race condition. This commit simply avoids performing this flushing for multires to allow for further iteration in the future instead of reverting the offending commit entirely.
Sean Kim added 1 commit 2024-07-23 02:33:14 +02:00
Sean Kim added this to the Sculpt, Paint & Texture project 2024-07-23 02:33:18 +02:00
Sean Kim requested review from Sergey Sharybin 2024-07-23 02:33:34 +02:00
Sean Kim requested review from Hans Goudey 2024-07-23 02:33:41 +02:00
Author
Member

For more information, the unreported issue that's alluded to in the original post of this PR is likely a race condition that I missed encountering when testing the initial implementation. That crash can be reproduced in current main, hence why I'm advocating to revert this in both this branch and in the 4.2 release branch.

Also, the reason the mask tool encounters this error in 4.2 but not in current main is because prior to 90c4c48bbf (diff-7ea99a817b555b40cfc6c3601aeb8a8de5048f54) the mask gestures would tag a normal update for multires for some reason. While removing this call in the 4.2 branch fixes the problem for the mask tool, the larger multires crash with sculpting on duplicated objects still remains.

For more information, the unreported issue that's alluded to in the original post of this PR is likely a race condition that I missed encountering when testing the initial implementation. That crash can be reproduced in current main, hence why I'm advocating to revert this in both this branch and in the 4.2 release branch. Also, the reason the mask tool encounters this error in 4.2 but not in current main is because prior to https://projects.blender.org/blender/blender/commit/90c4c48bbf1fe0000d82316ea5196bac394aeefb#diff-7ea99a817b555b40cfc6c3601aeb8a8de5048f54 the mask gestures would tag a normal update for multires for some reason. While removing this call in the 4.2 branch fixes the problem for the mask tool, the larger multires crash with sculpting on duplicated objects still remains.
Author
Member

An alternative here is to apply the following fix to simply ignore this update for multires, I'm currently undecided if this seems less risky & worth doing. It has the benefit of keeping curve stroke normals working for normal meshes:

diff --git a/source/blender/blenkernel/intern/paint.cc b/source/blender/blenkernel/intern/paint.cc
index dc6512bebd9..401fe3bc4ff 100644
--- a/source/blender/blenkernel/intern/paint.cc
+++ b/source/blender/blenkernel/intern/paint.cc
@@ -2049,7 +2049,7 @@ void BKE_sculpt_update_object_before_eval(Object *ob_eval)
 
   if (ss && ss->building_vp_handle == false) {
     if (!ss->cache && !ss->filter_cache && !ss->expand_cache) {
-      if (ss->pbvh && BKE_pbvh_type(*ss->pbvh) != PBVH_GRIDS) {
+      if (ss->pbvh) {
         /* PBVH nodes may contain dirty normal tags. To avoid losing that information when the PBVH
          * is deleted, make sure all tagged geometry normals are up to date.
          * See #122947 for more information. */
An alternative here is to apply the following fix to simply ignore this update for multires, I'm currently undecided if this seems less risky & worth doing. It has the benefit of keeping curve stroke normals working for normal meshes: ``` diff --git a/source/blender/blenkernel/intern/paint.cc b/source/blender/blenkernel/intern/paint.cc index dc6512bebd9..401fe3bc4ff 100644 --- a/source/blender/blenkernel/intern/paint.cc +++ b/source/blender/blenkernel/intern/paint.cc @@ -2049,7 +2049,7 @@ void BKE_sculpt_update_object_before_eval(Object *ob_eval) if (ss && ss->building_vp_handle == false) { if (!ss->cache && !ss->filter_cache && !ss->expand_cache) { - if (ss->pbvh && BKE_pbvh_type(*ss->pbvh) != PBVH_GRIDS) { + if (ss->pbvh) { /* PBVH nodes may contain dirty normal tags. To avoid losing that information when the PBVH * is deleted, make sure all tagged geometry normals are up to date. * See #122947 for more information. */ ```

I think it will be fine to go with your suggestion about BKE_pbvh_type(*ss->pbvh) != PBVH_GRIDS. Just add a comment with a reference to the report/PR, to make it easier to re-iterate in the future.

I think it will be fine to go with your suggestion about `BKE_pbvh_type(*ss->pbvh) != PBVH_GRIDS`. Just add a comment with a reference to the report/PR, to make it easier to re-iterate in the future.
Sean Kim added 2 commits 2024-07-23 16:05:26 +02:00
Sean Kim added 1 commit 2024-07-23 16:10:33 +02:00
Sean Kim changed title from Revert "Fix #122947: Curve stroke on duplicate object doesn't update normals" to Fix #125157: Sculpt multires crashes on box mask and duplicated stroke 2024-07-23 16:12:27 +02:00
Sergey Sharybin approved these changes 2024-07-23 16:23:44 +02:00
@ -2052,1 +2052,3 @@
if (ss->pbvh) {
/* Avoid performing the following normal update for Multires, as it causes race conditions
* and other intermittent crashes with shared meshes.
* See !125268 and #125157 for more information. */

. */ -> . */

`. */` -> `. */`
Sean-Kim marked this conversation as resolved
Sean Kim added 1 commit 2024-07-23 16:43:51 +02:00
Hans Goudey approved these changes 2024-07-23 22:16:06 +02:00
Hans Goudey left a comment
Member

Yes, just reverting the change for multires makes sense to me.

Yes, just reverting the change for multires makes sense to me.
Sean Kim added 2 commits 2024-07-23 22:51:00 +02:00
Sean Kim merged commit 338140f1e6 into main 2024-07-23 22:56:45 +02:00
Sean Kim deleted branch fix-125157 2024-07-23 22:56:48 +02:00
First-time contributor
image 4.2 building errors with: if (ss->pbvh && ss->pbvh->type() != blender::bke::pbvh::Type::Grids) { image

but: if (ss->pbvh && BKE_pbvh_type(*ss->pbvh) != PBVH_GRIDS) { compiled fine
image

<img width="920" alt="image" src="attachments/01d8b596-234d-4d8e-abd7-f67ec87fa94d"> 4.2 building errors with: if (ss->pbvh && ss->pbvh->type() != blender::bke::pbvh::Type::Grids) { <img width="893" alt="image" src="attachments/383499c8-9e25-4489-95ab-64888b69ac10"> but: if (ss->pbvh && BKE_pbvh_type(*ss->pbvh) != PBVH_GRIDS) { compiled fine <img width="917" alt="image" src="attachments/d79b5aee-e0ed-4e9e-8ce9-3a5be947f82c">
First-time contributor

Refactored in 4.3 with this commit: 7daefd730b

Refactored in 4.3 with this commit: https://projects.blender.org/blender/blender/commit/7daefd730b2c16c52f27bf9d5cf8adf17e4de41f
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
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
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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 Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#125268
No description provided.