Impossible to run Modal operator with simultaneously open props dialog (Blender crashes) #93478

Open
opened 2021-11-29 15:44:08 +01:00 by Andrei Tihonovschi · 7 comments

System Information
Operating system: Linux-5.15.4-x86_64-AMD_Ryzen_3_PRO_4350G_with_Radeon_Graphics-with-glibc2.33 64 Bits
Graphics card: AMD RENOIR (DRM 3.42.0, 5.15.4, LLVM 13.0.0) AMD 4.6 (Core Profile) Mesa 21.2.6

Blender Version
Broken: version: 2.93.0, branch: master, commit date: 2021-06-02 11:21, hash: 84da05a8b8
2.93.6, 2.93.7, 3.0.0 and 3.1.0 all are broken.
Worked: (don't know)

Short description of error
Blender crashes while trying to display operator properties dialog (invoke_props_dialog) and add
the same operator as the modal handler (modal_handler_add(self))
I think it's the same problem as in the (closed) task blender/blender-addons#48196

Exact steps for others to reproduce the error
Try to invoke corresponding operator and then to return {'FINISHED'} or {'CANCELLED'} from the modal() handler.
Then blender crashes after pressing ESC or closing dialog.

Sample code:

import bpy

class TEST(bpy.types.Operator):
    bl_idname = "test.modal"
    bl_label = "test invoke props + modal"

    test: bpy.props.StringProperty(
        name="test",
        description="test",
        default=''
    )
    
    def draw(self, context):
        col = self.layout.column(align=True)
        col.prop(self, "test")

    def invoke(self, context, event):
        context.window_manager.invoke_props_dialog(self)
        context.window_manager.modal_handler_add(self)
        return {'RUNNING_MODAL'}
    
    def execute(self, context):
        return {'FINISHED'}

    def modal(self, context, event):
        if event.type in {'ESC'}:
            return {'CANCELLED'}
        return {'PASS_THROUGH'}

def register():
    bpy.utils.register_class(TEST)


def unregister():
    bpy.utils.unregister_class(TEST)

if __name__ == "__main__":
    register()

I think that impossibility of creating modal operators which can simultaneously have open properties
dialog for on-the-fly corrections lead to endless tries to create custom bgl-rendered UIs which is just
an unneeded overhead.

Please, review the mentioned bug, AFAIK it was already fixed but somehow reappeared upstream...

**System Information** Operating system: Linux-5.15.4-x86_64-AMD_Ryzen_3_PRO_4350G_with_Radeon_Graphics-with-glibc2.33 64 Bits Graphics card: AMD RENOIR (DRM 3.42.0, 5.15.4, LLVM 13.0.0) AMD 4.6 (Core Profile) Mesa 21.2.6 **Blender Version** Broken: version: 2.93.0, branch: master, commit date: 2021-06-02 11:21, hash: `84da05a8b8` 2.93.6, 2.93.7, 3.0.0 and 3.1.0 all are broken. Worked: (don't know) **Short description of error** Blender crashes while trying to display operator properties dialog (invoke_props_dialog) and add the same operator as the modal handler (modal_handler_add(self)) I think it's the same problem as in the (closed) task blender/blender-addons#48196 **Exact steps for others to reproduce the error** Try to invoke corresponding operator and then to return {'FINISHED'} or {'CANCELLED'} from the modal() handler. Then blender crashes after pressing ESC or closing dialog. Sample code: ```python import bpy class TEST(bpy.types.Operator): bl_idname = "test.modal" bl_label = "test invoke props + modal" test: bpy.props.StringProperty( name="test", description="test", default='' ) def draw(self, context): col = self.layout.column(align=True) col.prop(self, "test") def invoke(self, context, event): context.window_manager.invoke_props_dialog(self) context.window_manager.modal_handler_add(self) return {'RUNNING_MODAL'} def execute(self, context): return {'FINISHED'} def modal(self, context, event): if event.type in {'ESC'}: return {'CANCELLED'} return {'PASS_THROUGH'} def register(): bpy.utils.register_class(TEST) def unregister(): bpy.utils.unregister_class(TEST) if __name__ == "__main__": register() ``` I think that impossibility of creating modal operators which can simultaneously have open properties dialog for on-the-fly corrections lead to endless tries to create custom bgl-rendered UIs which is just an unneeded overhead. Please, review the mentioned bug, AFAIK it was already fixed but somehow reappeared upstream...

Added subscriber: @atgote

Added subscriber: @atgote

Added subscriber: @mano-wii

Added subscriber: @mano-wii

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

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

Thanks for the report, I can confirm the crash with the example operator.
But it doesn't seem to be conventional to use invoke_props_dialog and modal_handler_add in the same operator.
The two modal operations are performed at the same time and both can free the operator, causing the one trying to use the operator later to crash.

I don't know what is the point of running an operator along with a popup, maybe it's better to separate the two things (Menu and operator).

Thanks for the report, I can confirm the crash with the example operator. But it doesn't seem to be conventional to use `invoke_props_dialog` and `modal_handler_add` in the same operator. The two modal operations are performed at the same time and both can free the operator, causing the one trying to use the operator later to crash. I don't know what is the point of running an operator along with a popup, maybe it's better to separate the two things (Menu and operator).

Just as an example - choose a "modifier" from Enum field which influences the operator action - and user can check the result before finalizing the operator execution (somewhat like with Undo/Redo dialog)

But the idea behind my search was to use modal handler to improve UX when using the props dialog. That is to have dialog responding to keypresses like add or remove (filter) / UI elements (props).
Something alike searching for an operator with operator search dialog (F3) but a little bit more powerful, allowing not only list-search, but UI-elements 'filter' - different operator/presets buttons for example.
That is - user may enter some keystrokes to filter available actions and then press the operator button or may just find the button in the list and press it without using filtering at all.

Just as an example - choose a "modifier" from Enum field which influences the operator action - and user can check the result before finalizing the operator execution (somewhat like with Undo/Redo dialog) But the idea behind my search was to use modal handler to improve UX when using the props dialog. That is to have dialog responding to keypresses like add or remove (filter) / UI elements (props). Something alike searching for an operator with operator search dialog (F3) but a little bit more powerful, allowing not only list-search, but UI-elements 'filter' - different operator/presets buttons for example. That is - user may enter some keystrokes to filter available actions and then press the operator button or may just find the button in the list and press it without using filtering at all.
Philipp Oeser removed the
Interest
Python API
label 2023-02-10 09:04:29 +01:00

Is there workaround for it? In my case I would like for user to be able to pick color, when he uses modal operator, by using context.window_manager.invoke_props_dialog(self) .
Answering my own question:

def draw_message_box(self,context):
    self.layout.label(text='bla')

context.window_manager.popover(self.draw_message_box, ui_units_x=32)
Is there workaround for it? In my case I would like for user to be able to pick color, when he uses modal operator, by using context.window_manager.invoke_props_dialog(self) . Answering my own question: ``` def draw_message_box(self,context): self.layout.label(text='bla') context.window_manager.popover(self.draw_message_box, ui_units_x=32) ```
Member

Why do you actually want to return {'FINISHED'} or {'CANCELLED'} from the modal if I may ask?

I mean I could imagine the crash being prevented by actually closing the dialog as well when the operator is freed from the modal, but I assume this is not what you are after either?

Why do you actually want to return {'FINISHED'} or {'CANCELLED'} from the modal if I may ask? I mean I could imagine the crash being prevented by actually closing the dialog as well when the operator is freed from the modal, but I assume this is not what you are after either?
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#93478
No description provided.