image datablocks report 1 user if they've ever been opened in the image editor but have no actual users. #89644

Closed
opened 2021-07-04 13:12:27 +02:00 by michael campbell · 12 comments

System Information
Operating system: Windows-10-10.0.19041-SP0 64 Bits
Graphics card: GeForce GTX 1070/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 461.92

Blender Version
Broken: version: 2.93.2 Release Candidate, branch: master, commit date: 2021-06-23 12:44, hash: 03d5c8b4ed
Worked: (newest version of Blender that worked as expected)

Short description of error
image datablocks report 1 user if they've ever been opened in the image editor but have no actual users.

Exact steps for others to reproduce the error

  • open a Compositor editor
  • add an image node
  • load in an image
  • add an Image editor to the workspace
  • select the image you loaded to view in the image editor
  • now remove it from the image editor by pressing the x, (or just choose another image to view)
  • delete the node that uses the image
    check in the blend data and you'll see it still has one user.

This is problematic, because it means you cant delete image datablocks via python if they have no users, because they always report as having one if they ever appeared in the image editor.

**System Information** Operating system: Windows-10-10.0.19041-SP0 64 Bits Graphics card: GeForce GTX 1070/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 461.92 **Blender Version** Broken: version: 2.93.2 Release Candidate, branch: master, commit date: 2021-06-23 12:44, hash: `03d5c8b4ed` Worked: (newest version of Blender that worked as expected) **Short description of error** image datablocks report 1 user if they've ever been opened in the image editor but have no actual users. **Exact steps for others to reproduce the error** - open a Compositor editor - add an image node - load in an image - add an Image editor to the workspace - select the image you loaded to view in the image editor - now remove it from the image editor by pressing the x, (or just choose another image to view) - delete the node that uses the image check in the blend data and you'll see it still has one user. This is problematic, because it means you cant delete image datablocks via python if they have no users, because they always report as having one if they ever appeared in the image editor.

Added subscriber: @3di

Added subscriber: @3di
Member

Added subscriber: @PratikPB2123

Added subscriber: @PratikPB2123

Added subscriber: @mano-wii

Added subscriber: @mano-wii

Changed status from 'Needs Triage' to: 'Needs User Info'

Changed status from 'Needs Triage' to: 'Needs User Info'

I'm not sure if the Compositor step is really needed to reproduce the described behavior.
If you load the image into the image editor and press the x, the users are not reset either.
This is the same behavior in older versions of Blender.
It's as if every added image already comes with 1 user by default.
You need to press Shift + X to make the amount of users 0.

Did I misunderstand the problem?

I'm not sure if the Compositor step is really needed to reproduce the described behavior. If you load the image into the image editor and press the x, the users are not reset either. This is the same behavior in older versions of Blender. It's as if every added image already comes with 1 user by default. You need to press Shift + X to make the amount of users 0. Did I misunderstand the problem?

Hi Germano, yes I think you may have misunderstood. You're only getting one user by default because you're creating the image from the image editor. If you create it elsewhere then the image editor won't count towards it's users (it'll still be one user (the actual user/node) until you open it in an image editor, then it'll be two users).

Basically I have some python code which needs to remove the image datablock if it's not in actual use by a part of blender which is using it for calculations. I don't think the UI should be classed as a user because there doesn't appear to be a way to differentiate between an actual user and a UI user, so you have to manually loop through and check everything in the blend file which could potentially be using that datablock, which isn't very performant.

Perhaps datablock.users could return a list of users rather than just an integer. Then the programmer could check they type of users and ignore those that are of type UI (if that is a type)

Hi Germano, yes I think you may have misunderstood. You're only getting one user by default because you're creating the image from the image editor. If you create it elsewhere then the image editor won't count towards it's users (it'll still be one user (the actual user/node) until you open it in an image editor, then it'll be two users). Basically I have some python code which needs to remove the image datablock if it's not in actual use by a part of blender which is using it for calculations. I don't think the UI should be classed as a user because there doesn't appear to be a way to differentiate between an actual user and a UI user, so you have to manually loop through and check everything in the blend file which could potentially be using that datablock, which isn't very performant. Perhaps datablock.users could return a list of users rather than just an integer. Then the programmer could check they type of users and ignore those that are of type UI (if that is a type)

Changed status from 'Needs User Info' to: 'Needs Developer To Reproduce'

Changed status from 'Needs User Info' to: 'Needs Developer To Reproduce'

Maybe the fact of viewing the image in the image editor adds 1 user is intentional?
The operator in X might intentionally avoid making the user quantity 0.
I have to study the code to be sure, but I still don't think it's a bug.

Maybe the fact of viewing the image in the image editor adds `1` user is intentional? The operator in `X` might intentionally avoid making the user quantity `0`. I have to study the code to be sure, but I still don't think it's a bug.

Added subscriber: @mont29

Added subscriber: @mont29

there is indeed no bug here, currently Blender relies on non-null user count to keep data-blocks around. 'shallow' users like image editors use a mechanism (check how LIB_TAG_EXTRAUSER/LIB_TAG_EXTRAUSER_SET are used in the code) that ensures that there is at least one user set when an image is assigned to an image editor e.g..

We have plans to change a bit how IDs are handled (and freed) by Blender in the future, see #61209 (Always write unused IDs on save). But currently this behavior is expected and definitely not a bug.

there is indeed no bug here, currently Blender relies on non-null user count to keep data-blocks around. 'shallow' users like image editors use a mechanism (check how `LIB_TAG_EXTRAUSER`/`LIB_TAG_EXTRAUSER_SET` are used in the code) that ensures that there is at least one user set when an image is assigned to an image editor e.g.. We have plans to change a bit how IDs are handled (and freed) by Blender in the future, see #61209 (Always write unused IDs on save). But currently this behavior is expected and definitely not a bug.

Changed status from 'Needs Developer To Reproduce' to: 'Archived'

Changed status from 'Needs Developer To Reproduce' to: 'Archived'

@mont29 should it not remove the user when pressing X in the image editor? And so that I can ignore the user if it's part of the UI, is there a way to differentiate in python between an actual user, and a UI user.....if not, is it possible to remove the user from the image editor and other UI elements via python? something like:

for img in bpy.data.images:

  if 'one of my images' in img:
      for ui in ui_users:
          if img.name in ui.images:
              ui.images.remove(img)
  

Cheers 👍

@mont29 should it not remove the user when pressing X in the image editor? And so that I can ignore the user if it's part of the UI, is there a way to differentiate in python between an actual user, and a UI user.....if not, is it possible to remove the user from the image editor and other UI elements via python? something like: for img in bpy.data.images: ``` if 'one of my images' in img: for ui in ui_users: if img.name in ui.images: ui.images.remove(img) ``` Cheers 👍
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
4 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#89644
No description provided.