2.8: Python API: crash due to missing window context in Application timer #62074

Closed
opened 2019-03-01 08:49:05 +01:00 by Marc · 23 comments

System Information
Operating system: Windows 7, 64bit
Graphics card: N/A

Blender Version
Broken:
2.80, dd9cedddae, win64

Short description of error

Error : EXCEPTION_ACCESS_VIOLATION
Address : 0x000000013F495468
Module : D:\Apps\blender-2.80.0-git.dd9cedddae69-windows64\blender.exe

This is related to #62051.

Exact steps for others to reproduce the error


import bpy


def add_cylinder():
    bpy.ops.mesh.primitive_cylinder_add(
        radius=1, depth=1,
        location=(1.5, 0.0, 1),
    )
    
    obj1 = bpy.context.scene.view_layers[0].objects.active
    obj1.select_set(True)
    bpy.ops.mesh.primitive_cylinder_add(
        radius=2, depth=1,
        location=(1.5, 0.0, 1),
    )
    obj2 = bpy.context.scene.view_layers[0].objects.active
    obj2.select_set(True)
    print(bpy.ops.object.join.poll())
    window = bpy.context.window_manager.windows[0]
    
    obs = [obj1, obj2]
    ctx = {'window': window, 'screen': window.screen}  
    ctx['object'] = obs[0]
    ctx['active_object'] = obs[0]
    ctx['selected_objects'] = obs
    ctx['selected_editable_objects'] = obs
    bpy.ops.object.mode_set(ctx, mode='OBJECT')
    bpy.ops.object.join(ctx)
    
    
# add_cylinder()   # this works
bpy.app.timers.register(add_cylinder)
**System Information** Operating system: Windows 7, 64bit Graphics card: N/A **Blender Version** Broken: 2.80, dd9cedddae69, win64 **Short description of error** Error : EXCEPTION_ACCESS_VIOLATION Address : 0x000000013F495468 Module : D:\Apps\blender-2.80.0-git.dd9cedddae69-windows64\blender.exe This is related to #62051. **Exact steps for others to reproduce the error** ``` import bpy def add_cylinder(): bpy.ops.mesh.primitive_cylinder_add( radius=1, depth=1, location=(1.5, 0.0, 1), ) obj1 = bpy.context.scene.view_layers[0].objects.active obj1.select_set(True) bpy.ops.mesh.primitive_cylinder_add( radius=2, depth=1, location=(1.5, 0.0, 1), ) obj2 = bpy.context.scene.view_layers[0].objects.active obj2.select_set(True) print(bpy.ops.object.join.poll()) window = bpy.context.window_manager.windows[0] obs = [obj1, obj2] ctx = {'window': window, 'screen': window.screen} ctx['object'] = obs[0] ctx['active_object'] = obs[0] ctx['selected_objects'] = obs ctx['selected_editable_objects'] = obs bpy.ops.object.mode_set(ctx, mode='OBJECT') bpy.ops.object.join(ctx) # add_cylinder() # this works bpy.app.timers.register(add_cylinder) ```
Author

Added subscriber: @schlamar

Added subscriber: @schlamar

blender/blender-addons#71422 was marked as duplicate of this issue

blender/blender-addons#71422 was marked as duplicate of this issue

blender/blender-addons#71317 was marked as duplicate of this issue

blender/blender-addons#71317 was marked as duplicate of this issue
Marc changed title from 2.8: Python API: Access violoation calling bpy.ops.object.mode_set in Application timer to 2.8: Python API: Access violation calling bpy.ops.object.mode_set in Application timer 2019-03-01 08:54:39 +01:00
Member

Added subscriber: @OmarEmaraDev

Added subscriber: @OmarEmaraDev
Member

System Information:
OS: Arch Linux with Xorg.

Blender Version:
Blender 2.80 (sub 45), Commit date: 2019-03-01 22:04, Hash 84820e7f58

Short description of error:
Invoking a window manager popup menu through a timer results in a segmentation fault and a crash. It seems the context window is null at this point.

Exact steps for others to reproduce the error:

A minimal working script that produces the problem:

import bpy

def in_5_seconds():
    bpy.context.window_manager.popup_menu(lambda self, context: None)

bpy.app.timers.register(in_5_seconds, first_interval=5)

Backtrace:

./blender(BLI_system_backtrace+0x1d) [0x1bb4bdd]
./blender() [0x115ad19]
/usr/lib/libc.so.6(+0x37e00) [0x7f70b7b17e00]
./blender(WM_window_pixels_x+0x4) [0x117f8f4]
./blender() [0x12fb565]
./blender(UI_block_begin+0x11d) [0x12fe34d]
./blender(UI_popup_menu_begin_ex+0x55) [0x1336b65]
./blender(WindowManager_popmenu_begin__internal_call+0x13) [0x1b317c3]
./blender(RNA_function_call+0x12) [0x1a437d2]
./blender() [0x150f74a]
./blender(_PyObject_FastCallKeywords+0x104) [0x2f8f784]
./blender(_PyEval_EvalFrameDefault+0x465c) [0x115272c]
./blender(_PyEval_EvalCodeWithName+0xae3) [0x3043973]
./blender(_PyFunction_FastCallKeywords+0xa6) [0x2f8f0e6]
./blender(_PyEval_EvalFrameDefault+0x79c3) [0x1155a93]
./blender() [0x114d020]
./blender(_PyFunction_FastCallDict+0x2a6) [0x2f8f026]
./blender() [0x15175da]
./blender(BLI_timer_execute+0x4a) [0x1b72b2a]
./blender(wm_event_do_notifiers+0x2e) [0x11655fe]
./blender(WM_main+0x28) [0x115b738]
./blender(main+0x30a) [0x10c123a]
/usr/lib/libc.so.6(__libc_start_main+0xf3) [0x7f70b7b04223]
./blender(_start+0x2a) [0x115769a]
**System Information:** OS: Arch Linux with Xorg. **Blender Version:** Blender 2.80 (sub 45), Commit date: 2019-03-01 22:04, Hash 84820e7f5806 **Short description of error:** Invoking a window manager popup menu through a timer results in a segmentation fault and a crash. It seems the context window is null at this point. **Exact steps for others to reproduce the error:** A minimal working script that produces the problem: ``` import bpy def in_5_seconds(): bpy.context.window_manager.popup_menu(lambda self, context: None) bpy.app.timers.register(in_5_seconds, first_interval=5) ``` Backtrace: ``` ./blender(BLI_system_backtrace+0x1d) [0x1bb4bdd] ./blender() [0x115ad19] /usr/lib/libc.so.6(+0x37e00) [0x7f70b7b17e00] ./blender(WM_window_pixels_x+0x4) [0x117f8f4] ./blender() [0x12fb565] ./blender(UI_block_begin+0x11d) [0x12fe34d] ./blender(UI_popup_menu_begin_ex+0x55) [0x1336b65] ./blender(WindowManager_popmenu_begin__internal_call+0x13) [0x1b317c3] ./blender(RNA_function_call+0x12) [0x1a437d2] ./blender() [0x150f74a] ./blender(_PyObject_FastCallKeywords+0x104) [0x2f8f784] ./blender(_PyEval_EvalFrameDefault+0x465c) [0x115272c] ./blender(_PyEval_EvalCodeWithName+0xae3) [0x3043973] ./blender(_PyFunction_FastCallKeywords+0xa6) [0x2f8f0e6] ./blender(_PyEval_EvalFrameDefault+0x79c3) [0x1155a93] ./blender() [0x114d020] ./blender(_PyFunction_FastCallDict+0x2a6) [0x2f8f026] ./blender() [0x15175da] ./blender(BLI_timer_execute+0x4a) [0x1b72b2a] ./blender(wm_event_do_notifiers+0x2e) [0x11655fe] ./blender(WM_main+0x28) [0x115b738] ./blender(main+0x30a) [0x10c123a] /usr/lib/libc.so.6(__libc_start_main+0xf3) [0x7f70b7b04223] ./blender(_start+0x2a) [0x115769a] ```
Member

Added subscriber: @JacquesLucke

Added subscriber: @JacquesLucke
Member

Can reproduce the crash.
Setting the priority to low for now.

As you've guessed correctly, there is no window context when the timer executes (obviously a window is needed to open a popup in Blender).

Can you check if it is possible to open the popup from within another operator which is called in the timer?
You need to pass some extra context into the operator as shown in #62078.

Can reproduce the crash. Setting the priority to `low` for now. As you've guessed correctly, there is no window context when the timer executes (obviously a window is needed to open a popup in Blender). Can you check if it is possible to open the popup from within another operator which is called in the timer? You need to pass some extra context into the operator as shown in #62078.
Member

@JacquesLucke Yes, the following script works as expected:

import bpy

class TestOperator(bpy.types.Operator):
    bl_idname = "scene.test_operator"
    bl_label = "Test Operator"

    def execute(self, context):
        context.window_manager.popup_menu(lambda self, context: None)
        return {'FINISHED'}

bpy.utils.register_class(TestOperator)

def in_5_seconds():
    window = bpy.context.window_manager.windows[0]
    ctx = {'window': window, 'screen': window.screen}  
    bpy.ops.scene.test_operator(ctx)

bpy.app.timers.register(in_5_seconds, first_interval=5)
@JacquesLucke Yes, the following script works as expected: ``` import bpy class TestOperator(bpy.types.Operator): bl_idname = "scene.test_operator" bl_label = "Test Operator" def execute(self, context): context.window_manager.popup_menu(lambda self, context: None) return {'FINISHED'} bpy.utils.register_class(TestOperator) def in_5_seconds(): window = bpy.context.window_manager.windows[0] ctx = {'window': window, 'screen': window.screen} bpy.ops.scene.test_operator(ctx) bpy.app.timers.register(in_5_seconds, first_interval=5) ```

Added subscriber: @JoseConseco

Added subscriber: @JoseConseco
Member

Added subscriber: @DanielGrauer

Added subscriber: @DanielGrauer

Since few days (around 11.june) timers will crash, if call for operator is performed inside. Simple blend file, just run script, and it will crash on line: 42

Blender Version: Broken: version: 2.80 (sub 74), branch: blender2.7, commit date: 2019-06-12 18:00, hash: 2404220e80

def every_2_seconds():
    ctx = get_default_context()
    bpy.ops.object.simple_operator(ctx) #crash here
    return 2.0

Timers_operator_crash.blend

Since few days (around 11.june) timers will crash, if call for operator is performed inside. Simple blend file, just run script, and it will crash on line: 42 Blender Version: Broken: version: 2.80 (sub 74), branch: blender2.7, commit date: 2019-06-12 18:00, hash: `2404220e80` ``` def every_2_seconds(): ctx = get_default_context() bpy.ops.object.simple_operator(ctx) #crash here return 2.0 ``` [Timers_operator_crash.blend](https://archive.blender.org/developer/F7103131/Timers_operator_crash.blend)
Philipp Oeser changed title from 2.8: Python API: Access violation calling bpy.ops.object.mode_set in Application timer to 2.8: Python API: crash due to missing window context in Application timer 2019-11-05 10:39:19 +01:00
Member

Added subscribers: @ianh, @lichtwerk

Added subscribers: @ianh, @lichtwerk

Added subscribers: @simon_lusenc, @mano-wii

Added subscribers: @simon_lusenc, @mano-wii

Added subscriber: @clepsydrae

Added subscriber: @clepsydrae

Added subscriber: @Zweistein

Added subscriber: @Zweistein

Can we set prio higher? I see new people writing issues about this quiet often and we need a fix.

Can we set prio higher? I see new people writing issues about this quiet often and we need a fix.

Added subscriber: @oweissbarth

Added subscriber: @oweissbarth
Member

Added subscriber: @VilemDuha

Added subscriber: @VilemDuha
Member

Actually, I'm getting crashes that come from calling an undo_push() operator with a context like this:

wm = bpy.data.window_managers[0]
w = wm.windows[0]
C_dict = {'window': w, 'screen': w.screen}

Not sure if this is a different issue and I should open a new report?

Actually, I'm getting crashes that come from calling an undo_push() operator with a context like this: wm = bpy.data.window_managers[0] w = wm.windows[0] C_dict = {'window': w, 'screen': w.screen} Not sure if this is a different issue and I should open a new report?
Member

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Jacques Lucke self-assigned this 2020-09-16 09:52:02 +02:00
Member

All the testable scripts provided in this report seem to work now (also see D8531 and D8532).

@VilemDuha I recommend you try using bpy.context.copy() and then overwrite entries in the returned dict. If that does not work, you can create a new report. Please provide a simple script that we can easily test.

All the testable scripts provided in this report seem to work now (also see [D8531](https://archive.blender.org/developer/D8531) and [D8532](https://archive.blender.org/developer/D8532)). @VilemDuha I recommend you try using `bpy.context.copy()` and then overwrite entries in the returned dict. If that does not work, you can create a new report. Please provide a simple script that we can easily test.
Member

@JacquesLucke I actually can't get it crashing with newest builds, that's great news.

@JacquesLucke I actually can't get it crashing with newest builds, that's great news.

Great job guys

Great job guys
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
12 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#62074
No description provided.