Blender 2.81 - Crash when deleting scene from timers API #71422

Closed
opened 2019-11-08 12:46:26 +01:00 by notallowed · 7 comments

System Information
Operating system: Linux-5.0.0-32-generic-x86_64-with-debian-buster-sid 64 Bits
Graphics card: GeForce GTX 1070 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 435.21

Blender Version
Broken: version: 2.81 (sub 16), branch: master, commit date: 2019-11-06 20:48, hash: blender/blender@85637311c2

Short description of error
Blender crashes if scene is deleted from timers API

Exact steps for others to reproduce the error

  1. Open blend file:
    scene_remove_crash.blend
  2. Run script.
  3. Crash.
**System Information** Operating system: Linux-5.0.0-32-generic-x86_64-with-debian-buster-sid 64 Bits Graphics card: GeForce GTX 1070 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 435.21 **Blender Version** Broken: version: 2.81 (sub 16), branch: master, commit date: 2019-11-06 20:48, hash: `blender/blender@85637311c2` **Short description of error** Blender crashes if scene is deleted from timers API **Exact steps for others to reproduce the error** 1. Open blend file: [scene_remove_crash.blend](https://archive.blender.org/developer/F7987704/scene_remove_crash.blend) 2. Run script. 3. Crash.
Author

Added subscriber: @simon_lusenc

Added subscriber: @simon_lusenc

Added subscriber: @mano-wii

Added subscriber: @mano-wii

I may be wrong, but I find it strange that CTX_wm_window(C) is NULL in this case.
Without getting into the real reason for the problem, this patch seems to solve the problem:

diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c
index 2c42dba9131..23ceedd63d0 100644
--- a/source/blender/makesrna/intern/rna_main_api.c
+++ b/source/blender/makesrna/intern/rna_main_api.c
@@ -183,15 +183,15 @@ static void rna_Main_scenes_remove(
 
   if ((scene_new = scene->id.prev) || (scene_new = scene->id.next)) {
     if (do_unlink) {
-      wmWindow *win = CTX_wm_window(C);
+      Scene *scene_act = CTX_data_scene(C);
 
-      if (WM_window_get_active_scene(win) == scene) {
+      if (scene_act == scene) {
 
 #  ifdef WITH_PYTHON
         BPy_BEGIN_ALLOW_THREADS;
 #  endif
 
-        WM_window_set_active_scene(bmain, C, win, scene_new);
+        CTX_data_scene_set(C, scene_new);
 
 #  ifdef WITH_PYTHON
         BPy_END_ALLOW_THREADS;

But I will wait for a second opinion.

I may be wrong, but I find it strange that `CTX_wm_window(C)` is `NULL` in this case. Without getting into the real reason for the problem, this patch seems to solve the problem: ``` diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c index 2c42dba9131..23ceedd63d0 100644 --- a/source/blender/makesrna/intern/rna_main_api.c +++ b/source/blender/makesrna/intern/rna_main_api.c @@ -183,15 +183,15 @@ static void rna_Main_scenes_remove( if ((scene_new = scene->id.prev) || (scene_new = scene->id.next)) { if (do_unlink) { - wmWindow *win = CTX_wm_window(C); + Scene *scene_act = CTX_data_scene(C); - if (WM_window_get_active_scene(win) == scene) { + if (scene_act == scene) { # ifdef WITH_PYTHON BPy_BEGIN_ALLOW_THREADS; # endif - WM_window_set_active_scene(bmain, C, win, scene_new); + CTX_data_scene_set(C, scene_new); # ifdef WITH_PYTHON BPy_END_ALLOW_THREADS; ``` But I will wait for a second opinion.
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Note there are similar reports open blender/blender#62074 (2.8: Python API: crash due to missing window context in Application timer), blender/blender#71383 (2.8: Python API: window's workspace can't be set in Application timer).

Workaround [before the main issue id fixed] [next to the solution @mano-wii provided] is to use an operator with a custom context:

import bpy

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

    def execute(self, context):
        bpy.data.scenes.remove(context.scene)
        return {'FINISHED'}

bpy.utils.register_class(TestOperator)

def tick():
    window = bpy.context.window_manager.windows[0]
    ctx = {'window': window, 'screen': window.screen, 'scene': bpy.data.scenes['Scene.001']}  
    bpy.ops.scene.test_operator(ctx)
    
    return 5.0

bpy.app.timers.register(tick)
Note there are similar reports open blender/blender#62074 (2.8: Python API: crash due to missing window context in Application timer), blender/blender#71383 (2.8: Python API: window's workspace can't be set in Application timer). Workaround [before the main issue id fixed] [next to the solution @mano-wii provided] is to use an operator with a custom context: ``` import bpy class TestOperator(bpy.types.Operator): bl_idname = "scene.test_operator" bl_label = "Test Operator" def execute(self, context): bpy.data.scenes.remove(context.scene) return {'FINISHED'} bpy.utils.register_class(TestOperator) def tick(): window = bpy.context.window_manager.windows[0] ctx = {'window': window, 'screen': window.screen, 'scene': bpy.data.scenes['Scene.001']} bpy.ops.scene.test_operator(ctx) return 5.0 bpy.app.timers.register(tick) ```
Member

@mano-wii: think we should merge this into blender/blender#62074? (since the underlying problem is really the same here...)
(next to your solution which seems good to have anyways? -- but would be sure on this one either...)

@mano-wii: think we should merge this into blender/blender#62074? (since the underlying problem is really the same here...) (next to your solution which seems good to have anyways? -- but would be sure on this one either...)

Closed as duplicate of blender/blender#62074

Closed as duplicate of blender/blender#62074
Sign in to join this conversation.
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-addons#71422
No description provided.