Undo incorrectly frees all the ImBufs of tiled images #97015

Closed
opened 2022-04-04 06:11:10 +02:00 by Jesse Yurkovich · 10 comments

System Information
Operating system: Windows-10-10.0.19044-SP0 64 Bits

Blender Version
Broken: branch: master from August 20th 2021 962153dbed
Worked: branch: master from August 19th 2021 a217e043be

Partially caused by: 0896457c59 with the following line in particular: ima->cache = NULL;
Removing that line allows 1-level of undo/redo to work correctly, but not multiple...

Short description of error
Undoing the addition of new image tiles for tiled images actually frees all ImBufs associated with the image.

Exact steps for others to reproduce the error

  • Open the Image Editor and create a new, tiled, image of any size
  • Add 1 or more image tiles to this image (from the side panel)
  • Undo (see below for an example)

Here's is what things look like after you create an Image, add 2 more tiles, and then add another 2 tiles:
before.png

Here's what it looks like after Undoing just once from that state:
after.png

**System Information** Operating system: Windows-10-10.0.19044-SP0 64 Bits **Blender Version** Broken: branch: master from August 20th 2021 `962153dbed` Worked: branch: master from August 19th 2021 `a217e043be` Partially caused by: 0896457c59 with the following line in particular: `ima->cache = NULL;` Removing that line allows 1-level of undo/redo to work correctly, but not multiple... **Short description of error** Undoing the addition of new image tiles for tiled images actually frees all ImBufs associated with the image. **Exact steps for others to reproduce the error** - Open the Image Editor and create a new, tiled, image of any size - Add 1 or more image tiles to this image (from the side panel) - Undo (see below for an example) Here's is what things look like after you create an Image, add 2 more tiles, and then add another 2 tiles: ![before.png](https://archive.blender.org/developer/F12967999/before.png) Here's what it looks like after Undoing just once from that state: ![after.png](https://archive.blender.org/developer/F12968001/after.png)
Author
Member

Added subscriber: @deadpin

Added subscriber: @deadpin
Member

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

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

Added subscribers: @Sergey, @Jeroen-Bakker, @brecht, @mont29

Added subscribers: @Sergey, @Jeroen-Bakker, @brecht, @mont29

From quick reading of code, it looks like content for tiles is only stored in the (supposedly runtime-only) Image.cache (BKE_image_fill_tile()...). So this issue does not only affect undo/redo, but also file save/reload, since this cache is never written nor read.

Am not sure what is going on here tbh, to me this looks like a giant mistake in code, but... maybe @Jeroen-Bakker, @brecht or @Sergey know better about this?

From quick reading of code, it looks like content for tiles is only stored in the (supposedly runtime-only) `Image.cache` (`BKE_image_fill_tile()`...). So this issue does not only affect undo/redo, but also file save/reload, since this cache is never written nor read. Am not sure what is going on here tbh, to me this looks like a giant mistake in code, but... maybe @Jeroen-Bakker, @brecht or @Sergey know better about this?

@mont29, this pointer is supposed to be restored through the BLOCacheStorage mechanism, but that's failing here.

It appears that BKE_idtype_cache_key_hash and BKE_idtype_cache_key_cmp take into account the cache value (ima->cache), which becomes NULL here. Using the cache value seems wrong for these functions, it's somewhat surprising this worked at all?

@mont29, this pointer is supposed to be restored through the `BLOCacheStorage` mechanism, but that's failing here. It appears that `BKE_idtype_cache_key_hash` and `BKE_idtype_cache_key_cmp` take into account the cache value (`ima->cache`), which becomes `NULL` here. Using the cache value seems wrong for these functions, it's somewhat surprising this worked at all?

@brecht this looks wrong indeed - although I guess it was working OK-ish before we started null-ifying runtime pointers on write...

But I don't think fixing this would fix the actual issue with generated image tiles. With regular generated image, its type is stored as part of the data, and can therefore be re-generated when the cached ImBuf is lost. With UDIM tiles, there is no data stored at all about them being generated image, so generated content is lost once cache is lost (on Undo currently, but also on file save/load e.g.). This sounds like a fairly weird design if that's the intended behavior...

And with that current design, fixing the broken cache handling on undo won't fix the issue on redo's, since the ImBuf's of the later-added tiles will be removed from the cache when undoing, they won't be available again on redo, leading to the exact same empty tiles issue again. Same problem if you try undoing tiles removal, and so on.


Regarding handling of caches across undo/redo: Think it makes no sense to use the cache pointer value in the key anymore indeed. Also found that current code (storing the cache value in the key, and then trying to use that as actual data value) is extremely bad design... Not proud of myself for having done that two years ago :(

See D14559 for a proposed fix for the cache handling issue itself. As already stated, this does not address all the issues at play here, by far.

@brecht this looks wrong indeed - although I guess it was working OK-ish before we started null-ifying runtime pointers on write... But I don't think fixing this would fix the actual issue with generated image tiles. With regular generated image, its type is stored as part of the data, and can therefore be re-generated when the cached ImBuf is lost. With UDIM tiles, there is no data stored at all about them being generated image, so generated content is lost once cache is lost (on Undo currently, but also on file save/load e.g.). This sounds like a fairly weird design if that's the intended behavior... And with that current design, fixing the broken cache handling on undo won't fix the issue on redo's, since the ImBuf's of the later-added tiles will be removed from the cache when undoing, they won't be available again on redo, leading to the exact same empty tiles issue again. Same problem if you try undoing tiles removal, and so on. ------------ Regarding handling of caches across undo/redo: Think it makes no sense to use the cache pointer value in the key anymore indeed. Also found that current code (storing the cache value in the key, and then trying to use that as actual data value) is extremely bad design... Not proud of myself for having done that two years ago :( See [D14559](https://archive.blender.org/developer/D14559) for a proposed fix for the cache handling issue itself. As already stated, this does not address all the issues at play here, by far.

The generated image parameters should really be stored per ImageTile. Looking through the Image struct, I don't see anything else that belongs there, all the other stuff seems like it should be shared.

The generated image parameters should really be stored per `ImageTile`. Looking through the `Image` struct, I don't see anything else that belongs there, all the other stuff seems like it should be shared.

This issue was referenced by e06399c223

This issue was referenced by e06399c223686aee7c2b6f9fb2db66a5f2cffad6

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Bastien Montagne self-assigned this 2022-04-11 15:02:34 +02:00

Created #97251 (Generated UDIM tiles do not store any info about their parameter) for the missing data storage in UDIM tiles, think this report itself can be closed now.

Created #97251 (Generated UDIM tiles do not store any info about their parameter) for the missing data storage in UDIM tiles, think this report itself can be closed now.
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
5 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#97015
No description provided.