Regression: Crash if you use the measure tool while changing certain user preferences in a 'depsgraph_update_post' handler #118223

Open
opened 2024-02-13 23:17:02 +01:00 by Ric-Lopez · 13 comments

Blender Version
Broken: version: 4.1.0 Alpha, branch: main, commit date: 2024-01-18 00:01, hash: d068407a004c
Worked: version: 4.1.0 Alpha, branch: main, commit date: 2024-01-11 21:04, hash: 16741e735b1b

Short description of error
If you have a handler of type depsgraph_update_post and this handler changes certain user preferences, Blender will crash when using the measure tool.

Example code to add the problematic handler:

import bpy
from bpy.app.handlers import persistent

@persistent
def my_handler(scene):
## The crash can happen if you add a measure while any of these values are edited:
# - bpy.context.preferences.view.show_navigate_ui
# - bpy.context.preferences.view.mini_axis_type
# - bpy.context.preferences.view.mini_axis_size
# - bpy.context.preferences.view.gizmo_size_navigate_v3d

## Or it can also happen if you change any theme preference:
    bpy.context.preferences.themes[0].view_3d.space.gradients.high_gradient = (0.50, 0.20, 0.20)

bpy.app.handlers.depsgraph_update_post.append(my_handler)

bpy.context.scene.update_tag() # Calls the handler

Exact steps for others to reproduce the error

  • Open attached .blend file
  • Run the script in the Text Editor
  • Select the measure tool,
  • Click on any part of the screen

Before I can even drag the tool, Blender Crashes.

**Blender Version** Broken: version: 4.1.0 Alpha, branch: main, commit date: 2024-01-18 00:01, hash: `d068407a004c` Worked: version: 4.1.0 Alpha, branch: main, commit date: 2024-01-11 21:04, hash: `16741e735b1b` **Short description of error** If you have a handler of type `depsgraph_update_post` and this handler changes certain user preferences, Blender will crash when using the measure tool. Example code to add the problematic handler: ```python import bpy from bpy.app.handlers import persistent @persistent def my_handler(scene): ## The crash can happen if you add a measure while any of these values are edited: # - bpy.context.preferences.view.show_navigate_ui # - bpy.context.preferences.view.mini_axis_type # - bpy.context.preferences.view.mini_axis_size # - bpy.context.preferences.view.gizmo_size_navigate_v3d ## Or it can also happen if you change any theme preference: bpy.context.preferences.themes[0].view_3d.space.gradients.high_gradient = (0.50, 0.20, 0.20) bpy.app.handlers.depsgraph_update_post.append(my_handler) bpy.context.scene.update_tag() # Calls the handler ``` **Exact steps for others to reproduce the error** - Open attached .blend file - Run the script in the Text Editor - Select the measure tool, - Click on any part of the screen Before I can even drag the tool, Blender Crashes.
Ric-Lopez added the
Priority
Normal
Type
Report
Status
Needs Triage
labels 2024-02-13 23:17:03 +01:00

Hi @Ric-Lopez,

Thank you for reporting this issue.

To investigate the crash with the measure tool in Blender 4.10 Beta, could you to provide us with crash logs? These logs can help us identify the cause of the crash and find a solution.

See: https://docs.blender.org/manual/en/dev/troubleshooting/crash.html#macos

Additionally, if you have any other information or error messages related to the crash, please let us know.

Hi @Ric-Lopez, Thank you for reporting this issue. To investigate the crash with the measure tool in Blender 4.10 Beta, could you to provide us with crash logs? These logs can help us identify the cause of the crash and find a solution. See: https://docs.blender.org/manual/en/dev/troubleshooting/crash.html#macos Additionally, if you have any other information or error messages related to the crash, please let us know.
Germano Cavalcante added
Status
Needs Information from User
and removed
Status
Needs Triage
labels 2024-02-14 01:53:30 +01:00
Author

Attached is the crash log - no additional messages came on screen

Attached is the crash log - no additional messages came on screen

Thank you for providing the crash log, @Ric-Lopez.
I analyzed the IPS file, but I didn't identify anything obvious that could indicate why it's crashing :\

Maybe the developers can figure it out (@Michael-Parkin-White-Apple ?).

Looking at the history of changes in the measure tool file, I also didn't find anything that could justify the regression.
https://projects.blender.org/blender/blender/commits/branch/main/source/blender/editors/space_view3d/view3d_gizmo_ruler.cc

I will forward it to our developers for further investigation. In the meantime, is there anything else you'd like to add or any other steps you think might have triggered the crash?
Also, if you have some time, could you test some archived development builds to try and find out which build the problem was introduced in?
https://builder.blender.org/download/daily/archive/

Thank you for providing the crash log, @Ric-Lopez. I analyzed the IPS file, but I didn't identify anything obvious that could indicate why it's crashing :\\ Maybe the developers can figure it out (@Michael-Parkin-White-Apple ?). Looking at the history of changes in the measure tool file, I also didn't find anything that could justify the regression. https://projects.blender.org/blender/blender/commits/branch/main/source/blender/editors/space_view3d/view3d_gizmo_ruler.cc I will forward it to our developers for further investigation. In the meantime, is there anything else you'd like to add or any other steps you think might have triggered the crash? Also, if you have some time, could you test some archived development builds to try and find out which build the problem was introduced in? https://builder.blender.org/download/daily/archive/
Author

Thank you for your review of the problem - there may be other issues , I never got past the measure tool crash - I will test again with a fresh install...

I Forgot to test without addons installed.....

I'll get back to you

Thank you for your review of the problem - there may be other issues , I never got past the measure tool crash - I will test again with a fresh install... I Forgot to test without addons installed..... I'll get back to you
Author

Ok, well Blender measure works fine in a fresh install - so it has to be an addon - what a pain to go throught them all to figure out where the problem is.....

Ok, well Blender measure works fine in a fresh install - so it has to be an addon - what a pain to go throught them all to figure out where the problem is.....
Germano Cavalcante added
Status
Needs Information from User
and removed
Status
Needs Triage
labels 2024-02-14 17:17:26 +01:00
Author

just to follow up - it was NONE of the addons

I was running a python script that wouls change the background color based on what mode I am in

ie Red for EDIT, Blue for SCULPT etc, as a visual cue of what I am doing - I found it helpful, but that caused the crash when I invoked the Measure tool in Blender 4.1

A copy of the script has been attached

I acually wish this could be added to Blender as a standard, it is really nice to know what mode you are in when multitasking other operations.

just to follow up - it was NONE of the addons I was running a python script that wouls change the background color based on what mode I am in ie Red for EDIT, Blue for SCULPT etc, as a visual cue of what I am doing - I found it helpful, but that caused the crash when I invoked the Measure tool in Blender 4.1 A copy of the script has been attached I acually wish this could be added to Blender as a standard, it is really nice to know what mode you are in when multitasking other operations.
Germano Cavalcante changed title from measure tool crash Blender 4.1 Beta to Regression: Crash if you use the measure tool while changing certain user preferences in a 'depsgraph_update_post' handler 2024-03-04 15:40:04 +01:00

Thanks for the update, I was able to replicate the crash and therefore updated the description.
Apologies for the delay in replying.

The step now is to bisect and find out where the problem was introduced.

Thanks for the update, I was able to replicate the crash and therefore updated the description. Apologies for the delay in replying. The step now is to bisect and find out where the problem was introduced.

Caused by da1ed32f76
@mont29 ^

Caused by da1ed32f7681071ecae24a8aab191ba31aa2fd5c @mont29 ^
Author

as I stated above, once I removed the custom python script (also attached above) the crash no longer occured

as I stated above, once I removed the custom python script (also attached above) the crash no longer occured

Can't check this right now (maybe @ideasman42 could have a look)... But in general editing data in a depsgraph_update handler is not the safest thing to do...

Can't check this right now (maybe @ideasman42 could have a look)... But in general editing data in a `depsgraph_update` handler is not the safest thing to do...

Note that the only change in da1ed32f76 that I could see causing this 'issue' is the addition of proper depsgraph update tagging in view3d_ruler_gpencil_ensure when adding a new GP ID. That could cause the bpy.context to have some invalid data at that point.

I would not expect accessing bpy.context from a depsgraph_update handler to be valid code. As in, I would not expect Blender to be able to guarantee that bpy.context is in a valid state at this point. Maybe @Sergey, @dr.sybren or @JacquesLucke know better about this topic though?

Note that the only change in da1ed32f76 that I could see causing this 'issue' is the addition of proper depsgraph update tagging in `view3d_ruler_gpencil_ensure` when adding a new GP ID. That could cause the `bpy.context` to have some invalid data at that point. I would not expect accessing `bpy.context` from a `depsgraph_update` handler to be valid code. As in, I would not expect Blender to be able to guarantee that `bpy.context` is in a valid state at this point. Maybe @Sergey, @dr.sybren or @JacquesLucke know better about this topic though?

You surely need to be careful what you access from the callback. Here it is not so much access to bpy.context which is a problem: I do not see how depsgraph_update_post could cause issues as it is running on the main thread, after the depsgraph is evaluated.

What happens here is the following:

  • A tweak gizmo is initialized
  • A modification to scene is done, and the scene is tagged for update
  • Depsgraph is updated, and it calls the update handler
  • Update handler modifies theme, which leads to gizmo system re-initialization
  • The measure operator is invoked, and it access gizmo, but the gizmo at this point does not exist due to the previous step
You surely need to be careful what you access from the callback. Here it is not so much access to `bpy.context` which is a problem: I do not see how `depsgraph_update_post` could cause issues as it is running on the main thread, after the depsgraph is evaluated. What happens here is the following: - A tweak gizmo is initialized - A modification to scene is done, and the scene is tagged for update - Depsgraph is updated, and it calls the update handler - Update handler modifies theme, which leads to gizmo system re-initialization - The measure operator is invoked, and it access gizmo, but the gizmo at this point does not exist due to the previous step

Not sure what to do here then, this sounds to me as a 'not expected to work' case?

In any case, does not really looks like a high-priority issue, again, manipulating data in handlers in general, and depsgraph handlers in particular, is risky (see also https://docs.blender.org/api/master/bpy.app.handlers.html#note-on-altering-data ).

Not sure what to do here then, this sounds to me as a 'not expected to work' case? In any case, does not really looks like a high-priority issue, again, manipulating data in handlers in general, and depsgraph handlers in particular, is risky (see also https://docs.blender.org/api/master/bpy.app.handlers.html#note-on-altering-data ).
Bastien Montagne added
Priority
Normal
and removed
Priority
High
labels 2024-03-07 12:41:30 +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
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#118223
No description provided.