bpy.app.driver_namespace: no way to properly initialize for driver in material #109720

Closed
opened 2023-07-05 03:15:58 +02:00 by Ilja Razinkov · 4 comments

System Information
Operating system: Windows-10-10.0.19045-SP0 64 Bits
Graphics card: NVIDIA GeForce RTX 2060 SUPER/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 531.79

Blender Version
Broken: version: 3.6.0, branch: blender-v3.6-release, commit date: 2023-06-27 08:08, hash: c7fc78b81ecb
Worked: version: 3.5.1, branch: blender-v3.5-release, commit date: 2023-04-24 18:11, hash: e1ccd9d4a1, type: release

Caused by 46be42f6b1

Short description of error
I have material with "value" node driven by driver. driver calls custom function from bpy.app.driver_namespace. bpy.app.driver_namespace populated with function in pre/post loading handler. Despite of that there is no function at load and initial render with that material gives wrong result. This worked well in 3.5.0

Exact steps for others to reproduce the error

  1. in Blender 3.6.0 open attached handle_driver_problem360.blend
  2. execute code in text block. This script adds pre/post loading handler. Both handlers add "dn_test" function to bpy.app.driver_namespace. this function used in material "value" node, with expression "dn_test(depsgraph)"
  3. reload the file. since handlers are installed, dn_test function should be added to namespace BEFORE evaluating driver in material, and material should have proper value upon opening (1.0). But this does not happen, upon loading the value is "0.0" and in console can be seen the reason:
Error in PyDriver: expression failed: dn_test(depsgraph)
For target: (type=NodeTree, name="Shader Nodetree", property=default_value, property_index=-1)

Traceback (most recent call last):
  File "<bpy driver>", line 1, in <module>
NameError: name 'dn_test' is not defined
  1. switch to "cycles" render mode, observe the objects are red (incorrect)

  2. Click on "value" node to update driver. at this time dn_test perfectly found and value updates to 1.0. Observe objects turn to green in viewport

  3. Repeat the same steps in Blender 3.5.1. Observer that after reload at step 3) "value" node have proper value 1.0 right from the start, and there is no errors in console

**System Information** Operating system: Windows-10-10.0.19045-SP0 64 Bits Graphics card: NVIDIA GeForce RTX 2060 SUPER/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 531.79 **Blender Version** Broken: version: 3.6.0, branch: blender-v3.6-release, commit date: 2023-06-27 08:08, hash: `c7fc78b81ecb` Worked: version: 3.5.1, branch: blender-v3.5-release, commit date: 2023-04-24 18:11, hash: e1ccd9d4a1d3, type: release Caused by 46be42f6b16314f59a37ebb430d77d12e7a88461 **Short description of error** I have material with "value" node driven by driver. driver calls custom function from bpy.app.driver_namespace. bpy.app.driver_namespace populated with function in pre/post loading handler. Despite of that there is no function at load and initial render with that material gives wrong result. This worked well in 3.5.0 **Exact steps for others to reproduce the error** 1) in Blender 3.6.0 open attached handle_driver_problem360.blend 2) execute code in text block. This script adds pre/post loading handler. Both handlers add "dn_test" function to bpy.app.driver_namespace. this function used in material "value" node, with expression "dn_test(depsgraph)" 3) reload the file. since handlers are installed, dn_test function should be added to namespace BEFORE evaluating driver in material, and material should have proper value upon opening (1.0). But this does not happen, upon loading the value is "0.0" and in console can be seen the reason: ``` Error in PyDriver: expression failed: dn_test(depsgraph) For target: (type=NodeTree, name="Shader Nodetree", property=default_value, property_index=-1) Traceback (most recent call last): File "<bpy driver>", line 1, in <module> NameError: name 'dn_test' is not defined ``` 4) switch to "cycles" render mode, observe the objects are red (incorrect) 5) Click on "value" node to update driver. at this time dn_test perfectly found and value updates to 1.0. Observe objects turn to green in viewport 6) Repeat the same steps in Blender 3.5.1. Observer that after reload at step 3) "value" node have proper value 1.0 right from the start, and there is no errors in console
Ilja Razinkov added the
Type
Report
Status
Needs Triage
Priority
Normal
labels 2023-07-05 03:15:58 +02:00
Member

From here 4.0, 3.6, 3.5.1 at e1ccd9d4a1 and 3.5.0 at cf82e5fe57 seems to be all broken, needs to click on the value for it to become green. Auto execution is on. I'm on linux.

Not sure if this is a intended use.

Here's what I have for output, this is just opening the file:

Error in PyDriver: expression failed: dn_test(depsgraph)
For target: (type=NodeTree, name="Shader Nodetree", property=default_value, property_index=-1)

name 'dn_test' is not defined

Traceback (most recent call last):
  File "<bpy driver>", line 1, in <module>
NameError: name 'dn_test' is not defined

Then click run script (nothing outputs, as expected), then File -> Revert:

Read blend: /home/yiming/Downloads/handle_driver_problem360.blend
Load Handler (PRE): /home/yiming/Downloads/handle_driver_problem360.blend None

Error in PyDriver: expression failed: dn_test(depsgraph)
For target: (type=NodeTree, name="Shader Nodetree", property=default_value, property_index=-1)

name 'dn_test' is not defined

Traceback (most recent call last):
  File "<bpy driver>", line 1, in <module>
NameError: name 'dn_test' is not defined
Load Handler (POST): /home/yiming/Downloads/handle_driver_problem360.blend None
From here 4.0, 3.6, 3.5.1 at e1ccd9d4a1 and 3.5.0 at cf82e5fe57c4 seems to be _all_ broken, needs to click on the value for it to become green. Auto execution is on. I'm on linux. Not sure if this is a intended use. Here's what I have for output, this is just opening the file: ``` Error in PyDriver: expression failed: dn_test(depsgraph) For target: (type=NodeTree, name="Shader Nodetree", property=default_value, property_index=-1) name 'dn_test' is not defined Traceback (most recent call last): File "<bpy driver>", line 1, in <module> NameError: name 'dn_test' is not defined ``` Then click run script (nothing outputs, as expected), then `File -> Revert`: ``` Read blend: /home/yiming/Downloads/handle_driver_problem360.blend Load Handler (PRE): /home/yiming/Downloads/handle_driver_problem360.blend None Error in PyDriver: expression failed: dn_test(depsgraph) For target: (type=NodeTree, name="Shader Nodetree", property=default_value, property_index=-1) name 'dn_test' is not defined Traceback (most recent call last): File "<bpy driver>", line 1, in <module> NameError: name 'dn_test' is not defined Load Handler (POST): /home/yiming/Downloads/handle_driver_problem360.blend None ```
YimingWu added the
Interest
Dependency Graph
Interest
Python API
labels 2023-07-05 04:43:27 +02:00
Author

Some clarification:

  • on first run error is normal, function not added. But on reload it is expected there is no errors and driver expression evaluated properly

  • regarding intended use - i am actually have an addon that setup a set of driver functions for my custom inhouse materials in PRE handler. Custom materials rely on this addon to be active, they use drivers that call my custom python methods. and "pre-load" handler seems to be a perfect place to setup up all the extras that are needed for materials in loading file. "pre-load" setup pythonic stuff, blender loads file and evaluates nodes with drivers bindings after that - and all the things expected to be in place at the time of first evaluation

  • i am using this scheme with inhouse materials+supplementary addon both on Windows and Mac, It worked perfectly well from 3.0 up to 3.5.1 this way.

Some clarification: - on first run error is normal, function not added. But on reload it is expected there is no errors and driver expression evaluated properly - regarding intended use - i am actually have an addon that setup a set of driver functions for my custom inhouse materials in PRE handler. Custom materials rely on this addon to be active, they use drivers that call my custom python methods. and "pre-load" handler seems to be a perfect place to setup up all the extras that are needed for materials in loading file. "pre-load" setup pythonic stuff, blender loads file and evaluates nodes with drivers bindings after that - and all the things expected to be in place at the time of first evaluation - i am using this scheme with inhouse materials+supplementary addon both on Windows and Mac, It worked perfectly well from 3.0 up to 3.5.1 this way.
Member

Can confirm, will check...

Can confirm, will check...
Philipp Oeser added
Status
Confirmed
and removed
Status
Needs Triage
labels 2023-07-20 11:36:05 +02:00
Member

Caused by 46be42f6b1

CC @ideasman42

Caused by 46be42f6b16314f59a37ebb430d77d12e7a88461 CC @ideasman42
Philipp Oeser added
Module
Python API
Priority
High
and removed
Priority
Normal
labels 2023-07-20 13:39:27 +02:00
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2023-07-25 07:43:11 +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
3 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#109720
No description provided.