Fix #109583: Avoid allocation new custom loop normals for write #109696

Closed
Iliya Katushenock wants to merge 6 commits from mod_moder:tmp_fix_data_race_to_compute_normals into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

3a3d9488a1 was cause memory leask for Curve Deform node.
And after few changes, this involk crash.
This used to be a leaked copy made by each node
to write its own version of the custom loop normals.

https://projects.blender.org/blender/blender/commit/3a3d9488a1633bfefabbab422dd22283bca02626 was cause memory leask for Curve Deform node. And after few changes, this involk crash. This used to be a leaked copy made by each node to write its own version of the custom loop normals.
Iliya Katushenock added the
Interest
Geometry Nodes
label 2023-07-04 15:18:28 +02:00
Iliya Katushenock added 5 commits 2023-07-04 15:18:38 +02:00
Iliya Katushenock added this to the Nodes & Physics project 2023-07-04 15:18:44 +02:00
Iliya Katushenock requested review from Jacques Lucke 2023-07-04 15:18:52 +02:00
Iliya Katushenock requested review from Hans Goudey 2023-07-04 15:18:52 +02:00
Hans Goudey reviewed 2023-07-04 16:14:38 +02:00
@ -1798,3 +1798,1 @@
/* may be nullptr */
blender::short2 *clnors = (blender::short2 *)CustomData_get_layer_for_write(
&mesh->ldata, CD_CUSTOMLOOPNORMAL, mesh->totloop);
/* May be nullptr. Const_cast to avoid data race while normals computing from different threads
Member

Suggestion for the comment:

May be null. The `const_cast` avoids reallocating the layer's data when making it mutable, which can result in memory leaks when this function is run from multiple threads. `clnors` is written to in rare cases when invalid data is found. Ideally they would not be written to, but this is the simplest way to maintain existing behavior.
Suggestion for the comment: ``` May be null. The `const_cast` avoids reallocating the layer's data when making it mutable, which can result in memory leaks when this function is run from multiple threads. `clnors` is written to in rare cases when invalid data is found. Ideally they would not be written to, but this is the simplest way to maintain existing behavior. ```
mod_moder marked this conversation as resolved
Iliya Katushenock added 1 commit 2023-07-04 16:22:38 +02:00
Member

Seems ok as a temporary solution, but will leave it to Hans to decide whether this is fine for now or whether a bigger change should be done first.

Seems ok as a temporary solution, but will leave it to Hans to decide whether this is fine for now or whether a bigger change should be done first.
Jacques Lucke refused to review 2023-07-10 13:44:30 +02:00
Member

Reading split_loop_nor_fan_do I'm a little less sure that this is okay. The "invalid" situation is when the custom normals in a smooth fan don't all match. The corners contained in smooth fans change as edges are marked sharp (or even as the mesh deforms with auto smooth). So if multiple differently deformed meshes share the same custom normals array, they will each write their own averaged custom normals into different groups of corners.

Without changing edge sharpness this isn't an issue, but I don't think we can just ignore that case unfortunately.

I think the proper solution, especially longer term, is to just avoid writing into custom normals completely. It just isn't a threadsafe thing to do, that's especially obvious in the drawing code. I started that here:

https://projects.blender.org/blender/blender/compare/main...HooglyBoogly:fix-no-custom-normals-write

When I'm back I'll take another look at that to make sure it doesn't have any unexpected consequences. But I don't really see any way around it for now.

Reading `split_loop_nor_fan_do` I'm a little less sure that this is okay. The "invalid" situation is when the custom normals in a smooth fan don't all match. The corners contained in smooth fans change as edges are marked sharp (or even as the mesh deforms with auto smooth). So if multiple differently deformed meshes share the same custom normals array, they will each write their own averaged custom normals into different groups of corners. Without changing edge sharpness this isn't an issue, but I don't think we can just ignore that case unfortunately. I think the proper solution, especially longer term, is to just avoid writing into custom normals completely. It just isn't a threadsafe thing to do, that's especially obvious in the drawing code. I started that here: https://projects.blender.org/blender/blender/compare/main...HooglyBoogly:fix-no-custom-normals-write When I'm back I'll take another look at that to make sure it doesn't have any unexpected consequences. But I don't really see any way around it for now.
Hans Goudey closed this pull request 2023-07-16 14:45:25 +02:00
Iliya Katushenock deleted branch tmp_fix_data_race_to_compute_normals 2023-07-16 14:52:40 +02:00

Pull request closed

Sign in to join this conversation.
No reviewers
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
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 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#109696
No description provided.