Opening Blender's File Chooser from a Dialog Causes Blender to Crash #65511

Closed
opened 2019-06-05 06:45:44 +02:00 by Grant Wilk · 9 comments

System Information
Operating system: Windows 10 Pro
Graphics card: (2x) NVIDIA GeForce GTX 1070

Blender Version
Broken: 2.80, c13e10a740, 2019-06-04
Worked: 2.79b, f4dc9f9d68, 2018-03-22

Short description of error
Creating a Python script that opens Blender's file chooser from a dialog will cause Blender to crash.

For ease of reproduction and demonstration, I have included a Blender file that contains a short Python script that causes this issue. The script is supposed to do the following once it is run:

  • Display a confirmation dialog asking the user if they would like to open a file chooser
  • Upon confirmation, open the file chooser.

Upon file selection, print the file's filepath to the console.

image.png

This code does functions properly in Blender 2.79b (hash mentioned above), but it causes a crash in Blender 2.80.

For some reason, using the execute function of the primary dialog operator, TEST_OT_primary_dialog, to call either of the file-chooser invoking operators, TEST_OT_invoke_file_chooser_1 or TEST_OT_invoke_file_chooser_2, causes Blender 2.80 to crash.

Exact steps for others to reproduce the error

  • Download and open the Blender file from below. It is a 2.79b file, but should open in 2.80 as well.
  • Click the "Run Script" button in the text editor. This will run the script and cause the primary dialog to open up.

Click "OK" to call the file-chooser operator from the primary dialog operator.

Demo Blender File (should open in 2.79b and 2.80):
2019_06_04_file_chooser_bug_b2_79.blend

Demo Code (for both 2.79 and 2.80):

import bpy
from bpy.types import Operator
from bpy_extras.io_utils import ImportHelper
from bpy.utils import register_class, unregister_class

- This operator shows a simple confirmation dialog that will
- invoke the operator that opens Blender's file chooser
class TEST_OT_primary_dialog(Operator):
    bl_idname = "test.primary_dialog"
    bl_label = "Primary Dialog"
    
    def draw(self, context):
        layout = self.layout
        layout.label(text="Open the file chooser?")
    
    def execute(self, context):
        
        - Both of these operator calls will cause the same behavior
        - despite using different methods.
        
        bpy.ops.test.invoke_file_chooser_1('INVOKE_DEFAULT')
        # bpy.ops.test.invoke_file_chooser_2('INVOKE_DEFAULT')    
        
        return {'FINISHED'}
     
    def invoke(self, context, event):
        wm = context.window_manager
        return wm.invoke_props_dialog(self)


- This operator will open Blender's file chooser when invoked
- and store the selected filepath in self.filepath and print it
# to the console using window_manager.fileselect_add()
class TEST_OT_invoke_file_chooser_1(Operator):
    bl_idname = "test.invoke_file_chooser_1"
    bl_label = "Submission Text 1"

    filepath = bpy.props.StringProperty(subtype='DIR_PATH')

    def execute(self, context):
        print(self.filepath)
        return {'FINISHED'}

    def invoke(self, context, event):
        context.window_manager.fileselect_add(self)
        return {'RUNNING_MODAL'}
    
    
- This operator will open Blender's file chooser when invoked
- and store the selected filepath in self.filepath and print it
# to the console using bpy_extra's ImportHelper
class TEST_OT_invoke_file_chooser_2(Operator, ImportHelper):
    bl_idname = "test.invoke_file_chooser_2"
    bl_label = "Submission Text 2"
    
    def execute(self, context):
        print(self.filepath)
        return {'FINISHED'}


# Register classes
register_class(TEST_OT_primary_dialog)
register_class(TEST_OT_invoke_file_chooser_1)
register_class(TEST_OT_invoke_file_chooser_2)


# Call the primary dialog operator
bpy.ops.test.primary_dialog('INVOKE_DEFAULT')
**System Information** Operating system: Windows 10 Pro Graphics card: (2x) NVIDIA GeForce GTX 1070 **Blender Version** Broken: 2.80, c13e10a7404d, 2019-06-04 Worked: 2.79b, f4dc9f9d68b, 2018-03-22 **Short description of error** Creating a Python script that opens Blender's file chooser from a dialog will cause Blender to crash. For ease of reproduction and demonstration, I have included a Blender file that contains a short Python script that causes this issue. The script is supposed to do the following once it is run: - Display a confirmation dialog asking the user if they would like to open a file chooser - Upon confirmation, open the file chooser. # Upon file selection, print the file's filepath to the console. ![image.png](https://archive.blender.org/developer/F7087879/image.png) This code does functions properly in Blender 2.79b (hash mentioned above), but it causes a crash in Blender 2.80. For some reason, using the execute function of the primary dialog operator, *TEST_OT_primary_dialog*, to call either of the file-chooser invoking operators, *TEST_OT_invoke_file_chooser_1* or *TEST_OT_invoke_file_chooser_2*, causes Blender 2.80 to crash. **Exact steps for others to reproduce the error** - Download and open the Blender file from below. It is a 2.79b file, but should open in 2.80 as well. - Click the "Run Script" button in the text editor. This will run the script and cause the primary dialog to open up. # Click "OK" to call the file-chooser operator from the primary dialog operator. Demo Blender File (should open in 2.79b and 2.80): [2019_06_04_file_chooser_bug_b2_79.blend](https://archive.blender.org/developer/F7087891/2019_06_04_file_chooser_bug_b2_79.blend) Demo Code (for both 2.79 and 2.80): ``` import bpy from bpy.types import Operator from bpy_extras.io_utils import ImportHelper from bpy.utils import register_class, unregister_class - This operator shows a simple confirmation dialog that will - invoke the operator that opens Blender's file chooser class TEST_OT_primary_dialog(Operator): bl_idname = "test.primary_dialog" bl_label = "Primary Dialog" def draw(self, context): layout = self.layout layout.label(text="Open the file chooser?") def execute(self, context): - Both of these operator calls will cause the same behavior - despite using different methods. bpy.ops.test.invoke_file_chooser_1('INVOKE_DEFAULT') # bpy.ops.test.invoke_file_chooser_2('INVOKE_DEFAULT') return {'FINISHED'} def invoke(self, context, event): wm = context.window_manager return wm.invoke_props_dialog(self) - This operator will open Blender's file chooser when invoked - and store the selected filepath in self.filepath and print it # to the console using window_manager.fileselect_add() class TEST_OT_invoke_file_chooser_1(Operator): bl_idname = "test.invoke_file_chooser_1" bl_label = "Submission Text 1" filepath = bpy.props.StringProperty(subtype='DIR_PATH') def execute(self, context): print(self.filepath) return {'FINISHED'} def invoke(self, context, event): context.window_manager.fileselect_add(self) return {'RUNNING_MODAL'} - This operator will open Blender's file chooser when invoked - and store the selected filepath in self.filepath and print it # to the console using bpy_extra's ImportHelper class TEST_OT_invoke_file_chooser_2(Operator, ImportHelper): bl_idname = "test.invoke_file_chooser_2" bl_label = "Submission Text 2" def execute(self, context): print(self.filepath) return {'FINISHED'} # Register classes register_class(TEST_OT_primary_dialog) register_class(TEST_OT_invoke_file_chooser_1) register_class(TEST_OT_invoke_file_chooser_2) # Call the primary dialog operator bpy.ops.test.primary_dialog('INVOKE_DEFAULT') ```
Author

Added subscriber: @remi_creative

Added subscriber: @remi_creative
Grant Wilk changed title from Opening Blender's File Chooser from Another Dialog Causes Blender to Crash to Opening Blender's File Chooser from a Dialog Causes Blender to Crash 2019-06-05 07:01:18 +02:00
Member

Added subscribers: @ideasman42, @JacquesLucke

Added subscribers: @ideasman42, @JacquesLucke
Member

The problem is probably that opening the file browser will close all popup dialogs.
Later, when the dialog tries to close itself, it does not exist anymore and it crashes.

Noticed that when I implemented the File Close Dialog (see wm_block_file_close_discard in 5ce3f69).

I see two possible solutions:

  1. Close the dialog before executing the callback.
  2. Don't close dialogs when the file browser opens. Maybe hide them?

Not sure what is preferable.

The problem is probably that opening the file browser will close all popup dialogs. Later, when the dialog tries to close itself, it does not exist anymore and it crashes. Noticed that when I implemented the File Close Dialog (see `wm_block_file_close_discard` in 5ce3f69). I see two possible solutions: 1. Close the dialog before executing the callback. 2. Don't close dialogs when the file browser opens. Maybe hide them? Not sure what is preferable.
Author

I just tested this issue again in the 2.80 release and it appears to be working now.
I'm not going to close the issue myself because I don't know if you guys have some sort of confirmation protocol, but I thought I'd update the thread!

I just tested this issue again in the 2.80 release and it appears to be working now. I'm not going to close the issue myself because I don't know if you guys have some sort of confirmation protocol, but I thought I'd update the thread!
Member

Added subscriber: @JulianEisel

Added subscriber: @JulianEisel
Member

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Julian Eisel self-assigned this 2019-09-09 10:56:47 +02:00
Member

Tested with the redesigned file browser in 2.81, seems to work without issues. Closing the report then :)

Tested with the redesigned file browser in 2.81, seems to work without issues. Closing the report then :)

Added subscriber: @vitorbalbio-3

Added subscriber: @vitorbalbio-3

Hi.
It works with ‘filepath’, ‘filename’ and ‘directory’ but crash using 'files'
Tested in blender 2.81 experimental version 970d7ed860

Hi. It works with ‘filepath’, ‘filename’ and ‘directory’ but crash using 'files' Tested in blender 2.81 experimental version 970d7ed860f1
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#65511
No description provided.