Certain operators (relying on context region) crash when called with INVOKE_AREA / EXEC_AREA #98491

Closed
opened 2022-05-30 12:00:21 +02:00 by yonghao lv · 12 comments

System Information
Operating system: Windows-10-10.0.22000-SP0 64 Bits
Graphics card: NVIDIA GeForce RTX 2080 SUPER/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 512.96

Blender Version
Broken: version: 3.2.0 Beta, branch: master, commit date: 2022-05-26 13:12, hash: bf53956914
Worked: --

Short description of the error
Certain operators (relying on context region) crash when called with INVOKE_AREA / EXEC_AREA

Steps to reproduce
execute this in blenders python console

bpy.ops.console.insert("INVOKE_AREA", text="crash")

So the reason for the crash is that an operator is invoked with INVOKE_AREA here (it does not crash with INVOKE_DEFAULT or any other Execution Context -- except for EXEC_AREA, same thing applies for that one, see below)

If INVOKE_AREA or EXEC_AREA is used, the region gets removed from context, see

      case WM_OP_EXEC_AREA:
      case WM_OP_INVOKE_AREA: {
        /* Remove region from context. */
        ARegion *region = CTX_wm_region(C);

        CTX_wm_region_set(C, nullptr);
        retval = wm_operator_invoke(C, ot, event, properties, reports, poll_only, true);
        CTX_wm_region_set(C, region);

Operators relying on / using region (e.g. via CTX_wm_region) can easily crash then.
Of course we could guard against this with a simple check (and this is done in a couple of places), not sure though if this is the smartest thing to do -- since there are many, many operators that would need the extra treatment...)

Original report
This script is use to check the active material, it can be run correct in the main window, but not popup window(change the pref window to node editor)

import bpy

bpy.ops.screen.userpref_show("INVOKE_AREA")
area = bpy.context.window_manager.windows[-1].screen.areas[0]


area.type = 'NODE_EDITOR'
flip_header = True
area.ui_type = 'ShaderNodeTree'
area.spaces[0].node_tree = bpy.data.materials['Material'].node_tree

for region in area.regions:
    if region.type == 'HEADER':
        with bpy.context.temp_override(area=area, region=region):
            if flip_header: bpy.ops.screen.region_flip('INVOKE_DEFAULT') # this line will not

    if region.type == 'WINDOW':
        with bpy.context.temp_override(area=area, region=region):
            bpy.ops.node.view_all("INVOKE_AREA") # this line will report context error

Exact steps for others to reproduce the error

**System Information** Operating system: Windows-10-10.0.22000-SP0 64 Bits Graphics card: NVIDIA GeForce RTX 2080 SUPER/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 512.96 **Blender Version** Broken: version: 3.2.0 Beta, branch: master, commit date: 2022-05-26 13:12, hash: `bf53956914` Worked: -- **Short description of the error** Certain operators (relying on context region) crash when called with `INVOKE_AREA` / `EXEC_AREA` **Steps to reproduce** execute this in blenders python console ```python bpy.ops.console.insert("INVOKE_AREA", text="crash") ``` So the reason for the crash is that an operator is invoked with INVOKE_AREA here (it does not crash with INVOKE_DEFAULT or any other Execution Context -- except for EXEC_AREA, same thing applies for that one, see below) If `INVOKE_AREA` or `EXEC_AREA` is used, the region gets removed from context, see ``` case WM_OP_EXEC_AREA: case WM_OP_INVOKE_AREA: { /* Remove region from context. */ ARegion *region = CTX_wm_region(C); CTX_wm_region_set(C, nullptr); retval = wm_operator_invoke(C, ot, event, properties, reports, poll_only, true); CTX_wm_region_set(C, region); ``` Operators relying on / using region (e.g. via CTX_wm_region) can easily crash then. Of course we could guard against this with a simple check (and this is done in a couple of places), not sure though if this is the smartest thing to do -- since there are many, many operators that would need the extra treatment...) **Original report** This script is use to check the active material, it can be run correct in the main window, but not popup window(change the pref window to node editor) ``` import bpy bpy.ops.screen.userpref_show("INVOKE_AREA") area = bpy.context.window_manager.windows[-1].screen.areas[0] area.type = 'NODE_EDITOR' flip_header = True area.ui_type = 'ShaderNodeTree' area.spaces[0].node_tree = bpy.data.materials['Material'].node_tree for region in area.regions: if region.type == 'HEADER': with bpy.context.temp_override(area=area, region=region): if flip_header: bpy.ops.screen.region_flip('INVOKE_DEFAULT') # this line will not if region.type == 'WINDOW': with bpy.context.temp_override(area=area, region=region): bpy.ops.node.view_all("INVOKE_AREA") # this line will report context error ``` **Exact steps for others to reproduce the error** - Open .blend file - Execute script [#98491.blend](https://archive.blender.org/developer/F13125231/T98491.blend)
Author

Added subscriber: @1029910278

Added subscriber: @1029910278
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

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

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

I am getting the wrong context, but no crash.

To avoid the context error, I think you need to set the nodetree explicitly?

area.type = 'NODE_EDITOR'
flip_header = True
area.ui_type = 'ShaderNodeTree'
area.spaces[0].node_tree = bpy.data.materials['Material'].node_tree

So:

I am getting the wrong context, but no crash. To avoid the context error, I think you need to set the nodetree explicitly? ``` area.type = 'NODE_EDITOR' flip_header = True area.ui_type = 'ShaderNodeTree' area.spaces[0].node_tree = bpy.data.materials['Material'].node_tree ``` So: - does setting the node_tree work for you? - do you have an idea on how to trigger the crash (intead of the error) - do you get crash logs? https://docs.blender.org/manual/en/3.3/troubleshooting/crash.html#windows
Author

This comment was removed by @1029910278

*This comment was removed by @1029910278*
Author

setting the node tree will be directly crash
area.spaces- [x].node_tree = bpy.context.object.active_material.node_tree
test1.crash.txt

previous crash
blender.crash.txt

setting the node tree will be directly crash `area.spaces- [x].node_tree = bpy.context.object.active_material.node_tree` [test1.crash.txt](https://archive.blender.org/developer/F13123049/test1.crash.txt) previous crash [blender.crash.txt](https://archive.blender.org/developer/F13123029/blender.crash.txt)
Member

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

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

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

Changed status from 'Needs Triage' to: 'Confirmed'
Philipp Oeser removed the
Interest
Nodes & Physics
label 2023-02-10 08:44:01 +01:00
Member

So the reason for the crash is that bpy.ops.node.view_all is invoked with INVOKE_AREA here (it does not crash with INVOKE_DEFAULT or any other Execution Context -- except for EXEC_AREA, same thing applies for that one, see below)

@1029910278 : is there any particular reason you are using INVOKE_AREA here?

If INVOKE_AREA or EXEC_AREA is used, the region gets removed from context, see

      case WM_OP_EXEC_AREA:
      case WM_OP_INVOKE_AREA: {
        /* Remove region from context. */
        ARegion *region = CTX_wm_region(C);

        CTX_wm_region_set(C, nullptr);
        retval = wm_operator_invoke(C, ot, event, properties, reports, poll_only, true);
        CTX_wm_region_set(C, region);

Operators relying on / using region (e.g. via CTX_wm_region) cn easily crash then.
Of course we could guard against this with a simple check (and this is done in a couple of places), not sure though if this is the smartest thing to do -- since there are many, many operators that would need the extra treatment...)

So the reason for the crash is that `bpy.ops.node.view_all` is invoked with `INVOKE_AREA` here (it does not crash with `INVOKE_DEFAULT` or any other Execution Context -- except for `EXEC_AREA`, same thing applies for that one, see below) @1029910278 : is there any particular reason you are using `INVOKE_AREA` here? If `INVOKE_AREA` or `EXEC_AREA` is used, the region gets removed from context, see ``` case WM_OP_EXEC_AREA: case WM_OP_INVOKE_AREA: { /* Remove region from context. */ ARegion *region = CTX_wm_region(C); CTX_wm_region_set(C, nullptr); retval = wm_operator_invoke(C, ot, event, properties, reports, poll_only, true); CTX_wm_region_set(C, region); ``` Operators relying on / using region (e.g. via `CTX_wm_region`) cn easily crash then. Of course we could guard against this with a simple check (and this is done in a couple of places), not sure though if this is the smartest thing to do -- since there are many, many operators that would need the extra treatment...)
Philipp Oeser changed title from popup window call operator will crash blender to Certain operators (relying on context region) crash when called with `INVOKE_AREA` / `EXEC_AREA` 2024-02-28 12:48:30 +01:00
Philipp Oeser added
Module
Python API
Interest
User Interface
and removed
Module
Nodes & Physics
labels 2024-02-28 12:49:01 +01:00
Member

Will raise prio (for @ideasman42 to consider lowering again) since it is a crasher

Will raise prio (for @ideasman42 to consider lowering again) since it is a crasher
Philipp Oeser added
Priority
High
and removed
Priority
Normal
labels 2024-02-28 12:59:36 +01:00

Probably these should just not exist, I can't think of a good purpose for them. They could probably be made to behave like EXEC_REGION_WIN and INVOKE_REGION_WIN and deprecated. But someone needs to check the few places we do use them and see if that change would cause any problems.

Probably these should just not exist, I can't think of a good purpose for them. They could probably be made to behave like `EXEC_REGION_WIN` and `INVOKE_REGION_WIN` and deprecated. But someone needs to check the few places we do use them and see if that change would cause any problems.

Even if INVOKE_AREA / EXEC_AREA are removed, the crashes will still exist since it's possible for the context's region to be null.
Another issue is the region might be set but not the desired type, so an operator may expect the window region but have a toolbar region, while it might not crash it's not going to work properly.

So AFAICS the operators poll function or the operators internal logic should be fixed either way.

Even if `INVOKE_AREA` / `EXEC_AREA` are removed, the crashes will still exist since it's possible for the context's region to be null. Another issue is the region might be set but not the desired type, so an operator may expect the window region but have a toolbar region, while it might not crash it's not going to work properly. So AFAICS the operators poll function or the operators internal logic should be fixed either way.
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2024-03-01 00:30:20 +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
5 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#98491
No description provided.