Cloning materials with too smart ShaderNodeCustomGroup breaks user counters of both source and target nodes #72317

Open
opened 2019-12-10 00:33:10 +01:00 by Maxim Vasiliev · 18 comments

System Information
Operating system: Linux-5.0.0-37-generic-x86_64-with-debian-buster-sid 64 Bits
Graphics card: GeForce GT 730/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 418.56

Blender Version
Broken: version: 2.82 (sub 4), branch: master, commit date: 2019-12-08 18:49, hash: 761111efb8
Worked: (optional)

Short description of error
Some of my shader nodes need to have separate node trees for each their copies.

It seems quite legal to do like this:

    def copy(self, node):
        self.node_tree = bpy.data.node_groups.new('newtree', 'ShaderNodeTree')

When the material is cloned (via ops.material.new), it makes the original tree.users == 0, and new tree.users == 2
Source node becomes zombie and dies after reloading or orphan cleaning.
Target node becomes undead and cannot die because of zero users.

Exact steps for others to reproduce the error

  1. run attached script from command line: blender --factory-startup --background --python test_op_mat_clone.py
  2. observe output: all trees are expected to have 1 users

test_op_mat_clone.py

**System Information** Operating system: Linux-5.0.0-37-generic-x86_64-with-debian-buster-sid 64 Bits Graphics card: GeForce GT 730/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 418.56 **Blender Version** Broken: version: 2.82 (sub 4), branch: master, commit date: 2019-12-08 18:49, hash: `761111efb8` Worked: (optional) **Short description of error** Some of my shader nodes need to have separate node trees for each their copies. It seems quite legal to do like this: ``` def copy(self, node): self.node_tree = bpy.data.node_groups.new('newtree', 'ShaderNodeTree') ``` When the material is cloned (via `ops.material.new`), it makes the original tree.users == 0, and new tree.users == 2 Source node becomes zombie and dies after reloading or orphan cleaning. Target node becomes undead and cannot die because of zero users. **Exact steps for others to reproduce the error** 1. run attached script from command line: `blender --factory-startup --background --python test_op_mat_clone.py` 2. observe output: all trees are expected to have 1 users [test_op_mat_clone.py](https://archive.blender.org/developer/F8233166/test_op_mat_clone.py)
Author

Added subscriber: @qwiglydee

Added subscriber: @qwiglydee
Author

This comment was removed by @qwiglydee

*This comment was removed by @qwiglydee*
Maxim Vasiliev changed title from Copying materials with custom nodes messes up users counters and may produce bogus orphaned and overused trees to Copying materials (or single-usering node groups) with custom nodes messes up users counters and may produce bogus orphaned and overused trees 2019-12-10 09:19:13 +01:00
Author

This comment was removed by @qwiglydee

*This comment was removed by @qwiglydee*

Added subscriber: @BYOB

Added subscriber: @BYOB
Maxim Vasiliev changed title from Copying materials (or single-usering node groups) with custom nodes messes up users counters and may produce bogus orphaned and overused trees to Cloning materials with too smart ShaderNodeCustomGroup breaks user counters of both source and target nodes 2019-12-19 02:37:47 +01:00
Member

Added subscriber: @JacquesLucke

Added subscriber: @JacquesLucke
Member

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

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

Please redo your tests and properly store a reference to a node tree in a node as described in https://developer.blender.org/T72579#839420.

Please redo your tests and properly store a reference to a node tree in a node as described in https://developer.blender.org/T72579#839420.

Added subscriber: @dfelinto

Added subscriber: @dfelinto

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

Changed status from 'Needs User Info' to: 'Archived'
Dalai Felinto self-assigned this 2020-01-13 18:34:46 +01:00

No activity for more than a week. As per the tracker policy we assume the issue is gone and can be closed.
Thanks again for the report. If the problem persists please open a new report with the required information.

No activity for more than a week. As per the tracker policy we assume the issue is gone and can be closed. Thanks again for the report. If the problem persists please open a new report with the required information.
Author

What is the policy, @dfelinto ?

Additional information is provided in referenced tasks.
The bug exists and it breakes and will break some shader add-ons.

Investigation is conducted, root cause of this and many other existing and potential bugs is discovered, fix is submitted, along with autotests.
What is a (more) proper way to help making blender better?

Do you have some kind of "fsck off, patches are not welcome" policy?

What is the policy, @dfelinto ? Additional information is provided in referenced tasks. The bug exists and it breakes and will break some shader add-ons. Investigation is conducted, root cause of this and many other existing and potential bugs is discovered, fix is submitted, along with autotests. What is a (more) proper way to help making blender better? Do you have some kind of "fsck off, patches are not welcome" policy?

Added subscriber: @rjg

Added subscriber: @rjg

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

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

@qwiglydee this is done more or less automatically for all open tickets that have the status Needs Information from User after a week without any activity. This is documented in the Triaging Playbook - No reply after a week . I guess this was unintentionally closed without checking the patches/progress and certainly your contributions are welcome.

I'll reopen the task.

@qwiglydee this is done more or less automatically for all open tickets that have the status `Needs Information from User` after a week without any activity. This is documented in the [Triaging Playbook - No reply after a week ](https://wiki.blender.org/wiki/Process/Bug_Reports/Triaging_Playbook). I guess this was unintentionally closed without checking the patches/progress and certainly your contributions are welcome. I'll reopen the task.
Author

Oh. Ok.

Then I'll put retated information here to avoid any non-automated confusion.

According to my debugging, the bug occurs because python method Node::copy is called from BKE_node_copy_ex, while refcounter of nested nodetree is in inconsistent state, and reinitializing node_tree inside the method breakes it even further.
The counters are corrected later in code of BKE_id_copy_ex, in the call of BKE_library_foreach_ID_link, after all material data is completely copied.

Proposed fix D6484 moves the call to supposedly more appropriate place.
A test for this case is in D6420.

Oh. Ok. Then I'll put retated information here to avoid any non-automated confusion. According to my debugging, the bug occurs because python method `Node::copy` is called from `BKE_node_copy_ex`, while refcounter of nested nodetree is in inconsistent state, and reinitializing `node_tree` inside the method breakes it even further. The counters are corrected later in code of `BKE_id_copy_ex`, in the call of `BKE_library_foreach_ID_link`, after all material data is completely copied. Proposed fix [D6484](https://archive.blender.org/developer/D6484) moves the call to supposedly more appropriate place. A test for this case is in [D6420](https://archive.blender.org/developer/D6420).
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

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

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

Can confirm.

Can confirm.
Dalai Felinto removed their assignment 2020-02-04 19:28:00 +01:00
Philipp Oeser removed the
Interest
Nodes & Physics
label 2023-02-10 08:47:09 +01: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
6 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#72317
No description provided.