Refactor and simplify Image (paint) undo code #85797

Closed
opened 2021-02-19 17:01:37 +01:00 by Bastien Montagne · 5 comments

At first, image undo type looks similar to Sculpt one, a differential type storing only differences from the previous undo step.

However, attempts to actually make it a proper differential ones have proved to be extremely difficult, mainly due to the overly complicated, under-documented current implementation. It seems to do something at one level, and then compensate backward for it at a lower level, and so on...

Here are some findings (which may or may not be correct/accurate) about current code:

  • Undo handling is similar to the sculpt one at top level (the image_undosys_step_decode callback), in that it undoes (un-applies) one step 'in the future' (un-applies step n+1 to get step n active).
  • But unlike sculpt code, during undo it will also process the target step n only if it is the final one.
  • Internally (uhandle_restore_list), each step stores two states, pre (the UndoImageBuf itself) and post (the UndoImageBuf.post buffer).
  • When redoing, the post state is always used to restore data.
  • When undoing, the prestate is always used to restore data, except for the final step, where the post one is used!
  • post state of step n seems to be shared with pre state of step n+1?

This looks overly complicated, and close to impossible to follow/change behavior, so really think it needs to be refactored and simplified into a fully differential design similar to Sculpt undo type. Or maybe into a fully stateful design, since all the tiles seem to be available in all steps anyway? Would then be similar to memfile or Edit mode undo's.

NOTE: There is no real urgency here, since current code has no known bugs. It's just impossible to maintain and make evolve, and it makes changes to higher-level undo system more risky/complicated since we basically have to deal with a black box here.

At first, image undo type looks similar to Sculpt one, a differential type storing only differences from the previous undo step. However, attempts to actually make it a proper differential ones have proved to be extremely difficult, mainly due to the overly complicated, under-documented current implementation. It seems to do something at one level, and then compensate backward for it at a lower level, and so on... Here are some findings (which may or may not be correct/accurate) about current code: * Undo handling is similar to the sculpt one at top level (the `image_undosys_step_decode` callback), in that it undoes (un-applies) one step 'in the future' (un-applies step `n+1` to get step `n` active). * But unlike sculpt code, during undo it will also process the target step `n` *only if it is the final one*. * Internally (`uhandle_restore_list`), each step stores two states, `pre` (the `UndoImageBuf` itself) and `post` (the `UndoImageBuf.post` buffer). * When redoing, the `post` state is always used to restore data. * When undoing, the `pre`state is always used to restore data, **except** for the final step, where the `post` one is used! * `post` state of step `n` seems to be shared with `pre` state of step `n+1`? This looks overly complicated, and close to impossible to follow/change behavior, so really think it needs to be refactored and simplified into a fully differential design similar to Sculpt undo type. Or maybe into a fully stateful design, since all the tiles seem to be available in all steps anyway? Would then be similar to memfile or Edit mode undo's. NOTE: There is no real urgency here, since current code has no known bugs. It's just impossible to maintain and make evolve, and it makes changes to higher-level undo system more risky/complicated since we basically have to deal with a black box here.
Author
Owner

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Author
Owner

Added subscriber: @mont29

Added subscriber: @mont29

Added subscriber: @Jenny-Brown

Added subscriber: @Jenny-Brown
Author
Owner

Changed status from 'Confirmed' to: 'Archived'

Changed status from 'Confirmed' to: 'Archived'
Author
Owner

This task is no more relevant as-is.

This task is no more relevant as-is.
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
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#85797
No description provided.