Stretch To constraints are broken on file reopening #127017

Open
opened 2024-08-31 15:05:02 +02:00 by Mark Raynsford · 9 comments

TL;DR:

Since validity of the constraints can change depending on the values of their ID pointers (e.g. targets), the remapping code needs to "somehow' update/re-check the constraints as part of its post-process updates.

Currently this happens in editor code area, when e.g. targets or other properties are edited (mainly through RNA and the property update callback system).

Proposed Solution

  1. Immediate 'simple' solution:
  • Move constraint_tag_update and whole related code into BKE.
  • Add another 'post-process' callback in remapping code, similar the the existing libblock_remap_data_postprocess_obdata_relink one, to call constraint_tag_update.
  • This will result in potentially (too) many calls to this constraint_tag_update function - to be confirmed.
  1. Proper, longer-term solution:
    a. Split constraint check/updates into two steps, an efficient and simple call to mark current status as dirty, and an actual 'ensure valid' code path only called 'when needed'.
    b. 'foreach id' handler for constraints checks if old and new ID are different, and accordingly tag the constraint as dirty, and the object as needing constraints status updates.

Technical Details of the Issue

The constraints in liboverride data are marked as valid, and therefore evaluated, while they should be invalid (and not evaluated). Here is what happens when applying liboverrides:

  1. liboverrides are applied by selectively assigning values from old, local liboverride data to a new, temporary copy of the reference linked data.
  2. When assigning the target to these StretchTo constraints, RNA update calls constraint_tag_update, which finds that the owner ID and the target ID are currently different, so it considers the constraint as valid.
  3. Then LibOverride apply code swap the two IDs, such that the new, updated liboverride now uses the same address as the old liboverride, and frees that old deprecated data. So now, the owner ID and the target ID are the same. But the constraint has already been checked as valid, and no re-check is performed.

Original Report:

System Information
Operating system: Linux
Graphics card: AMD Radeon RX 5600

Blender Version
Broken: Blender 4.2.1 LTS, 396f546c9d, 2024-08-20
Worked: None

Short description of error

Stretch To constraints on linked armatures are broken on file reopening.

Exact steps for others to reproduce the error

This issue was originally discussed as an issue with the Human Generator addon (https://github.com/OliverJPost/HumGen3D/issues/110), however it doesn't seem to be the fault of the addon. The model and rig included in the file is the output of the Human Generator 3D addon, but I've verified that the problem happens without the addon being present in the system (and the included blend should contain no references to the addon).

The steps required are as follows:

  • Create a new blend and delete all objects, leaving only the Scene Collection.

  • Link following objects in the attached BlenderLibraryOverrideBug.blend file into the new blend: Jeffery_RIGIFY, HG_Body, HG_Eyes, HG_TeethLower, HG_TeethUpper

  • Select the Jeffery_RIGIFY armature, and Make library override.

  • Save the file and reopen it.

You'll be greeted with the horrors in the image:

https://ataxia.io7m.com/2024/08/31/stretch.png

It makes an artistic statement, but it's not really what I wanted.

# TL;DR: Since validity of the constraints can change depending on the values of their ID pointers (e.g. targets), the remapping code needs to "somehow' update/re-check the constraints as part of its post-process updates. Currently this happens in `editor` code area, when e.g. targets or other properties are edited (mainly through RNA and the property update callback system). # Proposed Solution 1. Immediate 'simple' solution: * [ ] Move `constraint_tag_update` and whole related code into BKE. * [ ] Add another 'post-process' callback in remapping code, similar the the existing `libblock_remap_data_postprocess_obdata_relink` one, to call `constraint_tag_update`. * This will result in potentially (too) many calls to this `constraint_tag_update` function - to be confirmed. 2. Proper, longer-term solution: a. Split constraint check/updates into two steps, an efficient and simple call to mark current status as dirty, and an actual 'ensure valid' code path only called 'when needed'. b. 'foreach id' handler for constraints checks if old and new ID are different, and accordingly tag the constraint as dirty, and the object as needing constraints status updates. # Technical Details of the Issue The constraints in liboverride data are marked as valid, and therefore evaluated, while they should be invalid (and not evaluated). Here is what happens when applying liboverrides: 1. liboverrides are applied by selectively assigning values from old, local liboverride data to a new, temporary copy of the reference linked data. 2. When assigning the target to these StretchTo constraints, RNA update calls `constraint_tag_update`, which finds that the owner ID and the target ID are currently different, so it considers the constraint as valid. 3. Then LibOverride apply code swap the two IDs, such that the new, updated liboverride now uses the same address as the old liboverride, and frees that old deprecated data. So now, the owner ID and the target ID are the same. But the constraint has already been checked as valid, and no re-check is performed. --------------------------- # Original Report: **System Information** Operating system: Linux Graphics card: AMD Radeon RX 5600 **Blender Version** Broken: Blender 4.2.1 LTS, 396f546c9d, 2024-08-20 Worked: None **Short description of error** Stretch To constraints on linked armatures are broken on file reopening. **Exact steps for others to reproduce the error** This issue was originally discussed as an issue with the Human Generator addon (https://github.com/OliverJPost/HumGen3D/issues/110), however it doesn't seem to be the fault of the addon. The model and rig included in the file is the output of the Human Generator 3D addon, but I've verified that the problem happens without the addon being present in the system (and the included blend should contain no references to the addon). The steps required are as follows: - Create a new blend and delete all objects, leaving only the Scene Collection. - Link following objects in the attached `BlenderLibraryOverrideBug.blend` file into the new blend: `Jeffery_RIGIFY`, `HG_Body`, `HG_Eyes`, `HG_TeethLower`, `HG_TeethUpper` - Select the `Jeffery_RIGIFY` armature, and `Make library override`. - Save the file and reopen it. You'll be greeted with the horrors in the image: https://ataxia.io7m.com/2024/08/31/stretch.png It makes an artistic statement, but it's not really what I wanted.
Mark Raynsford added the
Severity
Normal
Type
Bug
Status
Needs Triage
labels 2024-08-31 15:05:03 +02:00
Member

Hi, thanks for the report. Can confirm after library override. AFAICS, HG_Eyes object's mesh data is corrupted (I ran mesh.validate()).
Apart from that, resyncing library override resolves the issue for an instance.
Not sure if this is a blender bug or somewhere in mesh/rig or corrupted data. @mont29 any idea?

Hi, thanks for the report. Can confirm after library override. AFAICS, `HG_Eyes` object's mesh data is corrupted (I ran `mesh.validate()`). Apart from that, resyncing library override resolves the issue for an instance. Not sure if this is a blender bug or somewhere in mesh/rig or corrupted data. @mont29 any idea?
Pratik Borhade added
Status
Needs Info from Developers
Interest
Overrides
and removed
Status
Needs Triage
labels 2024-09-04 11:03:23 +02:00

Analyzing a complete production rig is not really an option. Do you happen to know which constraint/bone is failing? Or can you reproduce the issue with a simple set-up (e.g. by taking current asset, and removing bones until you cannot reproduce the issue).

Analyzing a complete production rig is not really an option. Do you happen to know which constraint/bone is failing? Or can you reproduce the issue with a simple set-up (e.g. by taking current asset, and removing bones until you cannot reproduce the issue).
Bastien Montagne added
Status
Needs Information from User
and removed
Status
Needs Info from Developers
labels 2024-09-04 12:36:02 +02:00
Author

I listed all of the bones that have Stretch To constraints on them, and went down the list one at a time turning the influence on and off to see which bones caused the damage above.

It seems that these two bones cause all of the issues (at least to my eyes):

ORG-spine
ORG-spine.003

Interestingly, just touching the influence control fixes the problem. It doesn't matter what the influence is set to afterwards. I can't see anything that would make these two bones special. To reiterate; I didn't create the rig, so unfortunately I don't know or understand how it's constructed. I might be able to get some input from the author of the addon.

I listed all of the bones that have `Stretch To` constraints on them, and went down the list one at a time turning the influence on and off to see which bones caused the damage above. It seems that these two bones cause all of the issues (at least to my eyes): ``` ORG-spine ORG-spine.003 ``` Interestingly, just touching the influence control fixes the problem. It doesn't matter what the influence is set to afterwards. I can't see anything that would make these two bones special. To reiterate; I didn't create the rig, so unfortunately I don't know or understand how it's constructed. I might be able to get some input from the author of the addon.

Thanks, that sounds like an update issue then... checking.

Thanks, that sounds like an update issue then... checking.

Can confirm the issues.

In fact, with this heavily simplified file, most of the ORG bones get invalid transform after re-opening the file containing a liboverride of the rig. As if evaluation was not happening, or was happening with invalid data or at the wrong time. I did check, all the RNA update code seems to be called as expected, with proper depsgraph tagging, so... quite puzzled with this one currently.

Can confirm the issues. In fact, with [this heavily simplified file](/attachments/9357cc3e-dfa9-47bb-9ba2-d61db15c7678), most of the `ORG` bones get invalid transform after re-opening the file containing a liboverride of the rig. As if evaluation was not happening, or was happening with invalid data or at the wrong time. I did check, all the RNA update code seems to be called as expected, with proper depsgraph tagging, so... quite puzzled with this one currently.

Finally understood the problem. The root of the issue is that these StretchTo constraints are invalid (they target the owner object (the rig), but with no bone target).

Note that the problem could also arise in many other circumstances, and is not intrisically related to liboverrides, but rather to our id remapping code.

I updated the description of the task with details about the problem and a proposed way to solve it.
I cannot tackle that in the coming days, and will need input from the Animation team anyway.

CC @dr.sybren

Finally understood the problem. The root of the issue is that these StretchTo constraints are invalid (they target the owner object (the rig), but with no bone target). Note that the problem could also arise in many other circumstances, and is not intrisically related to liboverrides, but rather to our id remapping code. I updated the description of the task with details about the problem and a proposed way to solve it. I cannot tackle that in the coming days, and will need input from the Animation team anyway. CC @dr.sybren
Bastien Montagne added
Interest
Animation & Rigging
and removed
Interest
Dependency Graph
labels 2024-09-06 11:50:19 +02:00
Bastien Montagne added this to the Module: Core project 2024-09-06 12:14:43 +02:00
Author

I'm not sure what the status of this is now.

Is there any workaround? Presumably "manipulate every bone every time you open the file".

I'm not sure what the status of this is now. Is there any workaround? Presumably "manipulate every bone every time you open the file".

@io7m the immediate work-around is to mute or fix your StretchTo constraints (to be valid, they should either target another object, or have an additional bone sub-target).

@io7m the immediate work-around is to mute or fix your StretchTo constraints (to be valid, they should either target another object, or have an additional bone sub-target).
Author

OK, thanks. I've reported this back to the HG author, but I've no idea if he's read any of this.

OK, thanks. I've reported this back to the HG author, but I've no idea if he's read any of this.
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
Code Documentation
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 & 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
Asset System
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline & 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
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#127017
No description provided.