Driver access to 'self' property is outdated when changed from app handler #77700
Labels
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
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
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#77700
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
System Information
Operating system: Windows 10
Graphics card:
Blender Version
Broken: 2.83
Worked: Tested as far back as 2.80 with no luck.
Short description of error
It seems that drivers which access 'self' properties remain outdated by one frame, when the 'self' property in question is updated on frame change with an app handler.
Exact steps for others to reproduce the error
Added subscriber: @bblanimation
Added subscriber: @dr.sybren
@bblanimation That's quite a lot of script for a minimal example. Are you sure it's not possible to reduce it? For example, is it really necessary for this issue to show up to have a
poll()
function that always returnsTrue
? Is tagging for redraw really necessary, or can aprint()
statement to the terminal suffice?Changed status from 'Needs Triage' to: 'Needs User Info'
Changed status from 'Needs User Info' to: 'Needs Triage'
@dr.sybren That's fair! I went ahead and reduced the code quite a bit, and refined the description a bit to help clarify things. Happy to add/adjust anything else if needed.
Changed status from 'Needs Triage' to: 'Needs User Info'
Added subscriber: @mano-wii
Changed status from 'Needs User Info' to: 'Needs Triage'
Oops my bad
Changed status from 'Needs Triage' to: 'Archived'
@bblanimation The code uses
bpy.context.view_layer
, which has been shown to be dangerous to access from drivers in #75553. The solution for that is currently under review (D8047). Basically any Python code that's run from a driver or a callback or anything else that gets a context or a dependency graph from Blender should be using that context/depsgraph, and notbpy.context
.This is not the root of the issue, though. The problem is caused by using
frame_change_post()
; this is called by Blender after the dependency graph has been evaluated (hence the 'post' in the name). This means that first the driver is evaluated, and only then is theupdate_test_value()
function called. The best way is to useframe_change_pre()
as a callback, as that is called before the depsgraph is evaluated for the next frame. Note that in this case the scene frame number is already set to the next frame. The 'pre' in the function name means 'before the depsgraph evaluation', and not 'before the frame changes'.Alternatively you can tag the cube for update with
obj.update_tag()
inupdate_test_value()
. When this is done from a frame-change-post handler, it will trigger a second evaluation of the depsgraph, making sure that the driver picks up the new value. This could be a less performant solution, though.In any case, this doesn't seem to be a bug in Blender.
Just a bit of Python education, because I can't help it:
print("Test value (%(fc)s):" % locals(), round(obj.test_value, 2))
-- damn, that's some complex stuff. Just write this:Same for this:
I think that can be rewritten as something more readable like this:
Where, after D8047 has been applied,
view_layer
should be obtained from the depsgraph that's passed to the driver.