Fix #108198: Particle hair crash when using Hair Dynamics #108480

Merged
Hans Goudey merged 2 commits from Chao-Li/blender:fix-hair-dynamics into blender-v3.6-release 2023-06-06 18:46:40 +02:00
Contributor

hair_out_mesh and hair_in_mesh implicitly shares edges. In hair_create_input_mesh(), edge data of hair_in_mesh needs to be updated and therefore are copied to a new location. In the subsequent frames, psys->clmd->clothObject->edges won't be updated and point to freed memory block. Therefore, Blender crashes.
By freeing hair_out_mesh first,

  1. in hair_create_input_mesh(), at least edge data copying is avoided
  2. psys->clmd->clothObject->edges always points to correct memory

However, since it's possible that similar situation will happen again by adding another strong user to the same CustomData in the future, it is safer to update psys->clmd->clothObject->edges for every frame as well.

hair_out_mesh and hair_in_mesh implicitly shares edges. In hair_create_input_mesh(), edge data of hair_in_mesh needs to be updated and therefore are copied to a new location. In the subsequent frames, psys->clmd->clothObject->edges won't be updated and point to freed memory block. Therefore, Blender crashes. By freeing hair_out_mesh first, 1. in hair_create_input_mesh(), at least edge data copying is avoided 2. psys->clmd->clothObject->edges always points to correct memory However, since it's possible that similar situation will happen again by adding another strong user to the same CustomData in the future, it is safer to update psys->clmd->clothObject->edges for every frame as well.
Iliya Katushenock added this to the Nodes & Physics project 2023-05-31 22:15:35 +02:00
Iliya Katushenock requested review from Hans Goudey 2023-05-31 22:15:53 +02:00
Chao Li force-pushed fix-hair-dynamics from 1653c9840c to 814dffe7bc 2023-06-01 19:17:40 +02:00 Compare
Member

@blender-bot build

@blender-bot build
Author
Contributor

I thought the tests passed on my machine... My apologies. Let me take a look.

I thought the tests passed on my machine... My apologies. Let me take a look.
Chao Li force-pushed fix-hair-dynamics from fd78260038 to e8aff144f2 2023-06-02 22:19:27 +02:00 Compare
Author
Contributor

I must've rebased before pushing. I rebased again. Now the tests should be good.

I must've rebased before pushing. I rebased again. Now the tests should be good.
Member

@blender-bot build

@blender-bot build
Author
Contributor

Now I think about it I feel like this PR is a performance improvement and a temporary fix. I think the real problem is not properly addressed: it is assumed that some CustomData won't be moved during computation. Let's say somehow a new piece of code is introduced and another strong user is added to the hair_in_mesh->edata, the hair dynamics will be broken again. We should always assume the CustomData can be moved to a new place, maybe?

Now I think about it I feel like this PR is a performance improvement and a temporary fix. I think the real problem is not properly addressed: it is assumed that some CustomData won't be moved during computation. Let's say somehow a new piece of code is introduced and another strong user is added to the hair_in_mesh->edata, the hair dynamics will be broken again. We should always assume the CustomData can be moved to a new place, maybe?
Chao Li changed title from Fix #108198: Particle hair crash when using Hair Dynamics to WIP: Fix #108198: Particle hair crash when using Hair Dynamics 2023-06-03 19:17:28 +02:00
Chao Li changed title from WIP: Fix #108198: Particle hair crash when using Hair Dynamics to Fix #108198: Particle hair crash when using Hair Dynamics 2023-06-03 22:50:11 +02:00
Author
Contributor

Added another commit to update edge in simulation data for every frame. Please let me know if there other better workarounds. Thank you.

Added another commit to update edge in simulation data for every frame. Please let me know if there other better workarounds. Thank you.
Member

Since the particle system is end of life, I'm not too concerned about whether this is the perfect solution. A workaround is fine, and this code looks reasonable.

Could you rebase the PR to target the blender-v3.6-release branch, since the bug exists there too? More info here: https://wiki.blender.org/wiki/Tools/Pull_Requests#Rebasing_a_Pull_Request

Thanks!

Since the particle system is end of life, I'm not too concerned about whether this is the perfect solution. A workaround is fine, and this code looks reasonable. Could you rebase the PR to target the `blender-v3.6-release` branch, since the bug exists there too? More info here: https://wiki.blender.org/wiki/Tools/Pull_Requests#Rebasing_a_Pull_Request Thanks!
Chao Li changed title from Fix #108198: Particle hair crash when using Hair Dynamics to Fix #108198: Particle hair crash when using Hair Dynamics 2023-06-05 16:40:21 +02:00
Chao-Li changed target branch from main to blender-v3.6-release 2023-06-05 16:40:24 +02:00
Chao Li force-pushed fix-hair-dynamics from 6fcc4d5fbd to fd78260038 2023-06-05 16:47:11 +02:00 Compare
Chao Li force-pushed fix-hair-dynamics from fd78260038 to 08f8b8b266 2023-06-05 16:48:16 +02:00 Compare
Author
Contributor

Got it.

I've rebased the PR. Tests look good on my machine.

Thank you.

Got it. I've rebased the PR. Tests look good on my machine. Thank you.
Hans Goudey merged commit a56df90931 into blender-v3.6-release 2023-06-06 18:46:40 +02:00
Chao Li deleted branch fix-hair-dynamics 2023-06-13 23:31:26 +02:00
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
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 Assignees
2 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#108480
No description provided.