Bone collections and bone collection membership are not handled properly when undoing in armature edit mode #111780

Closed
opened 2023-09-01 10:58:07 +02:00 by Nathan Vegdahl · 1 comment
Member

Blender Version
Broken: 998136f7a7

Short description of error

When you undo in armature edit mode, all bones lose their bone collection memberships, and adding/removing bone collections is not undone.

Exact steps for others to reproduce the error

  1. Create an armature.
  2. Enter edit mode.
  3. Add some bones and collections, and assign some bones to some collections.
  4. Repeatedly undo, and see that bone collection membership is lost on all bones, and the operations adding bone collections don't get undone.

This is due to bone collections not being handled at all in the armature undo code.


In order to initially land bone collections, I added the following code as a stop-gap to avoid crashes due to accessing invalid memory:

619f38514e/source/blender/editors/armature/armature_utils.cc (L871-L881)

It does indeed eliminate the crashes, but also causes undo to work incorrectly. To fix this issue, that code must be removed, and all crashes and misbehavior resulting from that need to be addressed.

**Blender Version** Broken: 998136f7a7b **Short description of error** When you undo in armature edit mode, all bones lose their bone collection memberships, and adding/removing bone collections is not undone. **Exact steps for others to reproduce the error** 1. Create an armature. 2. Enter edit mode. 3. Add some bones and collections, and assign some bones to some collections. 4. Repeatedly undo, and see that bone collection membership is lost on all bones, and the operations adding bone collections don't get undone. This is due to bone collections not being handled at all in the armature undo code. ---- In order to initially land bone collections, I added the following code as a stop-gap to avoid crashes due to accessing invalid memory: https://projects.blender.org/blender/blender/src/commit/619f38514e9908456936b0be64ea9cc565c3c8fb/source/blender/editors/armature/armature_utils.cc#L871-L881 It does indeed eliminate the crashes, but also causes undo to work incorrectly. To fix this issue, that code must be removed, and all crashes and misbehavior resulting from that need to be addressed.
Nathan Vegdahl added the
Status
Confirmed
Priority
High
Type
Bug
Module
Animation & Rigging
labels 2023-09-01 10:59:01 +02:00
Nathan Vegdahl self-assigned this 2023-09-01 10:59:09 +02:00
Author
Member

Further investigation into the crashes revealed that there are multiple underlying issues, any of which can cause crashes:

  1. The armature undo code in editors/armature/editarmature_undo.cc copies the edit bones to the undo stack, for later restoration. However, it doesn't copy the collection membership listbase, so the undo copy of an edit bone points to the same listbase memory as the edit bone still in the armature. If the latter gets deleted, the collection membership listbase also gets deleted, and the undo edit bone is then pointing at invalid memory. This issue is relatively straightforward to address, by simply doing proper copy of that membership listbase... except that will still interact badly with the remaining issues.
  2. The armature undo code in editors/armature/editarmature_undo.cc doesn't handle bone collections at all. This means that adding/removing collections while in armature edit mode doesn't get undone. That on its own needs to get fixed just because it's faulty undo behavior. But it also can result in invalid memory access, due to the collection membership listbase stored in the undo edit bones. If a collection is removed, and then you undo, one of the edit bones may still be pointing to the removed collection. But even after fixing things to restore removed collections on undo, they presumably will not have the same memory address, so the undo edit bones will still point to invalid memory.
  3. Outside of edit mode, undo is handled by copying data from a memory file. So even if we fix both of the above issues to work properly within edit mode, undoing outside of edit mode frees and recreates the bone collections, so the edit-mode undo stack will again have edit bones pointing at invalid memory via their collection membership listbase. And this also leads to crashes when object-mode undo and edit-mode undo interact, which is fairly easy to trigger.
Further investigation into the crashes revealed that there are multiple underlying issues, any of which can cause crashes: 1. The armature undo code in `editors/armature/editarmature_undo.cc` copies the edit bones to the undo stack, for later restoration. However, it doesn't copy the collection membership listbase, so the undo copy of an edit bone points to the same listbase memory as the edit bone still in the armature. If the latter gets deleted, the collection membership listbase also gets deleted, and the undo edit bone is then pointing at invalid memory. This issue is relatively straightforward to address, by simply doing proper copy of that membership listbase... except that will still interact badly with the remaining issues. 2. The armature undo code in `editors/armature/editarmature_undo.cc` doesn't handle bone collections *at all*. This means that adding/removing collections while in armature edit mode doesn't get undone. That on its own needs to get fixed just because it's faulty undo behavior. But it *also* can result in invalid memory access, due to the collection membership listbase stored in the undo edit bones. If a collection is removed, and then you undo, one of the edit bones may still be pointing to the removed collection. But even after fixing things to restore removed collections on undo, they presumably will not have the same memory address, so the undo edit bones will *still* point to invalid memory. 3. Outside of edit mode, undo is handled by copying data from a memory file. So even if we fix both of the above issues to work properly *within* edit mode, undoing outside of edit mode frees and recreates the bone collections, so the edit-mode undo stack will again have edit bones pointing at invalid memory via their collection membership listbase. And this also leads to crashes when object-mode undo and edit-mode undo interact, which is fairly easy to trigger.
Sybren A. Stüvel added this to the 4.0 milestone 2023-09-05 15:07:32 +02:00
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2023-09-11 18:28:28 +02: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
1 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#111780
No description provided.