Delete scene operator used in script crashes blender #44376

Closed
opened 2015-04-13 23:35:10 +02:00 by Andrej Ivanis · 12 comments

pyth_bug.blend

I made this simple operator that just executes delete scene operator:

class DeleteSceneDoop(bpy.types.Operator):
    bl_idname = "pbr.del_scn_doop"
    bl_label = "Delete Scene Doop"
    
    @classmethod
    def poll(cls, context):
        return bpy.ops.scene.delete.poll()
    
    def execute(self, c):
        if bpy.ops.scene.delete.poll():
            bpy.ops.scene.delete()
        return {'FINISHED'}

It works fine when I run it from 3D View. But if I run it from properties area Blender will crash, while the original Delete Scene operator works fine.

To reproduce:
Open the file
Press Run Script
Go over the properties area with the mouse pointer
Search for 'Delete Scene Doop'
Press enter
The crash should happen

Blender version: 2.74
OS X 10.9.5 (Macbook Retina)

[pyth_bug.blend](https://archive.blender.org/developer/F161679/pyth_bug.blend) I made this simple operator that just executes delete scene operator: ``` class DeleteSceneDoop(bpy.types.Operator): bl_idname = "pbr.del_scn_doop" bl_label = "Delete Scene Doop" @classmethod def poll(cls, context): return bpy.ops.scene.delete.poll() def execute(self, c): if bpy.ops.scene.delete.poll(): bpy.ops.scene.delete() return {'FINISHED'} ``` It works fine when I run it from 3D View. But if I run it from properties area Blender will crash, while the original Delete Scene operator works fine. To reproduce: Open the file Press Run Script Go over the properties area with the mouse pointer Search for 'Delete Scene Doop' Press enter The crash should happen Blender version: 2.74 OS X 10.9.5 (Macbook Retina)
Author

Changed status to: 'Open'

Changed status to: 'Open'
Author

Added subscriber: @aivanis

Added subscriber: @aivanis
Member

Added subscriber: @Blendify

Added subscriber: @Blendify

Added subscriber: @Sergey

Added subscriber: @Sergey
Campbell Barton was assigned by Sergey Sharybin 2015-04-14 11:26:38 +02:00

Added subscriber: @ideasman42

Added subscriber: @ideasman42

@ideasman42, do you mind having a look here?

@ideasman42, do you mind having a look here?

Added subscriber: @brecht

Added subscriber: @brecht

Campbell, do you think this is an acceptable fix? I don't think there's a good way to remove the scene from the context.

diff --git a/release/scripts/modules/bpy/ops.py b/release/scripts/modules/bpy/ops.py
index d3d9255..052deb3 100644
--- a/release/scripts/modules/bpy/ops.py
+++ b/release/scripts/modules/bpy/ops.py
@@ -146,11 +146,12 @@ class BPyOpsSubModOp:

     @staticmethod
     def _scene_update(context):
+        import bpy
         scene = context.scene
-        if scene:  # None in background mode
+        # scene can be None in background mode or deleted by the operator
+        if scene and scene in bpy.data.scenes.values():
             scene.update()
         else:
-            import bpy
             for scene in bpy.data.scenes:
                 scene.update()
Campbell, do you think this is an acceptable fix? I don't think there's a good way to remove the scene from the context. ``` diff --git a/release/scripts/modules/bpy/ops.py b/release/scripts/modules/bpy/ops.py index d3d9255..052deb3 100644 --- a/release/scripts/modules/bpy/ops.py +++ b/release/scripts/modules/bpy/ops.py @@ -146,11 +146,12 @@ class BPyOpsSubModOp: @staticmethod def _scene_update(context): + import bpy scene = context.scene - if scene: # None in background mode + # scene can be None in background mode or deleted by the operator + if scene and scene in bpy.data.scenes.values(): scene.update() else: - import bpy for scene in bpy.data.scenes: scene.update() ```

This issue was referenced by blender/blender@77e6a001a9

This issue was referenced by blender/blender@77e6a001a96b7eb3b2b1c2216a48c85c1b6906e0

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'

Closed by commit blender/blender@77e6a001a9.

Closed by commit blender/blender@77e6a001a9.

@brecht, thanks for looking into this... your suggested fix solves this bug in a pretty direct way,
but we had other bugs reported regarding stale pointers in the button-space and further API calls could still crash.
so I prefer to go for a more general fix which we can apply for other errors accessing data from buttons context, also it could get slow with 100's or scenes.

Since unlinking the scene is already checking the button space's pinid, I've added a callback which runs from BKE_spacedata_id_unref to avoid bad level calls.

@brecht, thanks for looking into this... your suggested fix solves this bug in a pretty direct way, but we had other bugs reported regarding stale pointers in the button-space and further API calls could still crash. so I prefer to go for a more general fix which we can apply for other errors accessing data from buttons context, also it could get slow with 100's or scenes. Since unlinking the scene is already checking the button space's `pinid`, I've added a callback which runs from `BKE_spacedata_id_unref` to avoid bad level calls.
Sign in to join this conversation.
No Milestone
No project
No Assignees
6 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#44376
No description provided.