Fix: Crash when parenting mesh to armature with automatic weights #118847

Merged
Sergey Sharybin merged 2 commits from Sergey/blender:workob into main 2024-02-28 15:06:10 +01:00

There probably are more cases where crash will happen as it is
rooting into the issue with BKE_object_workob_calc_parent() which
is used in multiple places.

The issue is caused by the access to a runtime field of workob
outside of the BKE_object_workob_calc_parent(): the runtime field
is stack-allocated in the function, and can not be accessed outside
of the function.

The easiest way to reproduce is to use ASAN, and parent mesh to an
armature with automatic weights. Although, on macOS ASAN did not
report issues, so setting workob->runtime to nullptr at the end of
of the BKE_object_workob_calc_parent() was the easiest.

The solution is simple: make the function to return the matrix,
and take care of the working object inside of it, so all tricky
parts are hidden from the API.

The patch is targeting the main branch, as in 4.1 it is not
required to do such change because all uses of the function only
access object_to_world, which is stored in the object in 4.1.

A double-check in the what_does_obaction() might be needed as it
follows the similar pattern, but it does not seem that runtime
field of the workob is accessed in usages of the what_does_obaction().

There probably are more cases where crash will happen as it is rooting into the issue with BKE_object_workob_calc_parent() which is used in multiple places. The issue is caused by the access to a runtime field of workob outside of the BKE_object_workob_calc_parent(): the runtime field is stack-allocated in the function, and can not be accessed outside of the function. The easiest way to reproduce is to use ASAN, and parent mesh to an armature with automatic weights. Although, on macOS ASAN did not report issues, so setting workob->runtime to nullptr at the end of of the BKE_object_workob_calc_parent() was the easiest. The solution is simple: make the function to return the matrix, and take care of the working object inside of it, so all tricky parts are hidden from the API. The patch is targeting the main branch, as in 4.1 it is not required to do such change because all uses of the function only access object_to_world, which is stored in the object in 4.1. A double-check in the what_does_obaction() might be needed as it follows the similar pattern, but it does not seem that runtime field of the workob is accessed in usages of the what_does_obaction().
Sergey Sharybin added 1 commit 2024-02-28 12:55:47 +01:00
Fix crash when parenting mesh to armature with automatic weights
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
e257f17eea
There probably are more cases where crash will happen as it is
rooting into the issue with BKE_object_workob_calc_parent() which
is used in multiple places.

The issue is caused by the access to a runtime field of workob
outside of the BKE_object_workob_calc_parent(): the runtime field
is stack-allocated in the function, and can not be accessed outside
of the function.

The easiest way to reproduce is to use ASAN, and parent mesh to an
armature with automatic weights. Although, on macOS ASAN did not
report issues, so setting workob->runtime to nullptr at the end of
of the BKE_object_workob_calc_parent() was the easiest.

The solution is simple: make the function to return the matrix,
and take care of the working object inside of it, so all tricky
parts are hidden from the API.

The patch is targeting the main branch, as in 4.1 it is not
required to do such change because all uses of the function only
access object_to_world, which is stored in the object in 4.1.

A double-check in the what_does_obaction() might be needed as it
follows the similar pattern, but it does not seem that runtime
field of the workob is accessed in usages of the what_does_obaction().
Author
Owner

@blender-bot build

@blender-bot build
Hans Goudey approved these changes 2024-02-28 14:36:47 +01:00
Dismissed
Hans Goudey left a comment
Member

Really nice to reduce the use of this "workob" pattern! It would be nice for what_does_obaction to just return the transformation (components) directly too, but that can be done later like you said. I couldn't spot any issues here, so looks good.

Really nice to reduce the use of this "workob" pattern! It would be nice for `what_does_obaction` to just return the transformation (components) directly too, but that can be done later like you said. I couldn't spot any issues here, so looks good.
@ -57,2 +59,3 @@
* \return calculated object_to_world.
*/
void BKE_object_workob_calc_parent(Depsgraph *depsgraph, Scene *scene, Object *ob, Object *workob);
blender::float4x4 BKE_object_workob_calc_parent(Depsgraph *depsgraph, Scene *scene, Object *ob);
Member

BKE_object_calc_parent sounds like a better name now. Or at least some name without workob. That could be committed separately if you liked though.

`BKE_object_calc_parent` sounds like a better name now. Or at least some name without `workob`. That could be committed separately if you liked though.
Author
Owner

This is a good point. Think its pretty fine to rename as part of this PR.

This is a good point. Think its pretty fine to rename as part of this PR.
Hans Goudey changed title from Fix crash when parenting mesh to armature with automatic weights to Fix: Crash when parenting mesh to armature with automatic weights 2024-02-28 14:36:59 +01:00
Sergey Sharybin added 1 commit 2024-02-28 14:53:03 +01:00
Also corrected commented-out code.
All in all, no functional changes expected.
Hans Goudey approved these changes 2024-02-28 15:03:55 +01:00
Sergey Sharybin merged commit 87a98c361c into main 2024-02-28 15:06:10 +01:00
Sergey Sharybin deleted branch workob 2024-02-28 15:06:13 +01:00
Sign in to join this conversation.
No reviewers
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 project
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#118847
No description provided.