Data race when lazily creating mesh normal layers #95839

Closed
opened 2022-02-17 16:44:36 +01:00 by Hans Goudey · 6 comments
Member

System Information
Operating system: Linux-5.16.8-200.fc35.x86_64-x86_64-with-glibc2.34 64 Bits
Graphics card: NVIDIA GeForce GTX 1080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 510.47.03

Blender Version
Broken: version: 3.2.0 Alpha, branch: master (modified), commit date: 2022-02-17 14:24, hash: a4c800ed02
Caused by: cfa53e0fbe
Worked: Not clear, but mesh normals refactor has buggy behavior either way

Short description of error
There is a race condition when accessing normals on meshes

Exact steps for others to reproduce the error
erosion_simulation.v01.blend

  • Open the file with a release build and the --debug argument
  • Blender should crash

The fundamental problem is that when the normals mutex is locked, a normal layer is added to meshes, which might reallocate CustomData.layers.
That's a problem, since normals can be created on a const mesh, which only works well if write access is properly protected.

Solutions
The problem in the file is fixed by P2802, which locks the normals mutex when copying a mesh.

There are a few potential solutions I would consider:

  1. Don't store mesh normals in CustomData, instead move them to Mesh_Runtime.
  • Pros
    • This starts a more proper separation of derived data and original data (maybe custom data should only ever store original data)
    • Further clarifies the "runtime-only" state of mesh normals.
  • Cons
    • Allocation and freeing isn't handled automatically by custom data.
    • Future copy-on-write improvements might involve more boilerplate.
  1. Ensure that a mesh always has CD_NORMAL layers, just don't always allocate its data.
  • Pros
    • Maybe a faster solution to implement
    • Reuses allocation/freeing/copy-on-write functionality from CustomData
  • Cons
    • We might want to move away from using CustomData in the longer term anyway
    • Doesn't clarify the original vs. derived data situation

Currently I think I prefer the first solution. If we went with that solution, eventually CD_NORMAL could actually be removed,
since a different custom data type is used to implement custom normals. Though derived face corner normals would have to be
refactored in the same way as vertex and face normals first.

**System Information** Operating system: Linux-5.16.8-200.fc35.x86_64-x86_64-with-glibc2.34 64 Bits Graphics card: NVIDIA GeForce GTX 1080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 510.47.03 **Blender Version** Broken: version: 3.2.0 Alpha, branch: master (modified), commit date: 2022-02-17 14:24, hash: `a4c800ed02` Caused by: cfa53e0fbe Worked: Not clear, but mesh normals refactor has buggy behavior either way **Short description of error** There is a race condition when accessing normals on meshes **Exact steps for others to reproduce the error** [erosion_simulation.v01.blend](https://archive.blender.org/developer/F12871380/erosion_simulation.v01.blend) - Open the file with a release build and the `--debug` argument - Blender should crash The fundamental problem is that when the normals mutex is locked, a normal layer is added to meshes, which might reallocate `CustomData.layers`. That's a problem, since normals can be created on a `const` mesh, which only works well if write access is properly protected. **Solutions** The problem in the file is fixed by [P2802](https://archive.blender.org/developer/P2802.txt), which locks the normals mutex when copying a mesh. There are a few potential solutions I would consider: 1. **Don't store mesh normals in `CustomData`, instead move them to `Mesh_Runtime`.** - Pros - This starts a more proper separation of derived data and original data (maybe custom data should only ever store original data) - Further clarifies the "runtime-only" state of mesh normals. - Cons - Allocation and freeing isn't handled automatically by custom data. - Future copy-on-write improvements might involve more boilerplate. 2. **Ensure that a mesh always has `CD_NORMAL` layers, just don't always allocate its data.** - Pros - Maybe a faster solution to implement - Reuses allocation/freeing/copy-on-write functionality from `CustomData` - Cons - We might want to move away from using `CustomData` in the longer term anyway - Doesn't clarify the original vs. derived data situation Currently I think I prefer the first solution. If we went with that solution, eventually `CD_NORMAL` could actually be removed, since a different custom data type is used to implement custom normals. Though derived face corner normals would have to be refactored in the same way as vertex and face normals first.
Author
Member

Added subscriber: @HooglyBoogly

Added subscriber: @HooglyBoogly
Author
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Author
Member

Added subscriber: @JacquesLucke

Added subscriber: @JacquesLucke
Member

I prefer the first approach as well. So better attempt that refactor first. If that turns out to be too complicated, we can probably come up with a quick fix that uses the second approach.

I prefer the first approach as well. So better attempt that refactor first. If that turns out to be too complicated, we can probably come up with a quick fix that uses the second approach.

This issue was referenced by 59343ee162

This issue was referenced by 59343ee1627f4c369e237cea201015b979da1540
Author
Member

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Hans Goudey self-assigned this 2022-02-22 18:45:02 +01:00
Thomas Dinges added this to the 3.1 milestone 2023-02-08 15:52:46 +01:00
Sign in to join this conversation.
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
3 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#95839
No description provided.