Add-on: prevent potentially crashing Blender

Prevent a potential crash of Blender. Calling
`context.window_manager.modal_handler_add(self)` from an operator that does
not actually run modally can cause problems. So now that's called only
when running modally.
This commit is contained in:
Sybren A. Stüvel 2024-06-25 17:49:06 +02:00
parent f7a1e92e82
commit 1056699e4a

@ -162,6 +162,8 @@ class FLAMENCO_OT_submit_job(FlamencoOpMixin, bpy.types.Operator):
is_running = self._submit_files(context, filepath) is_running = self._submit_files(context, filepath)
if not is_running: if not is_running:
return {"CANCELLED"} return {"CANCELLED"}
context.window_manager.modal_handler_add(self)
return {"RUNNING_MODAL"} return {"RUNNING_MODAL"}
def modal(self, context: bpy.types.Context, event: bpy.types.Event) -> set[str]: def modal(self, context: bpy.types.Context, event: bpy.types.Event) -> set[str]:
@ -383,7 +385,6 @@ class FLAMENCO_OT_submit_job(FlamencoOpMixin, bpy.types.Operator):
self._quit(context) self._quit(context)
return False return False
context.window_manager.modal_handler_add(self)
wm = context.window_manager wm = context.window_manager
self.timer = wm.event_timer_add(self.TIMER_PERIOD, window=context.window) self.timer = wm.event_timer_add(self.TIMER_PERIOD, window=context.window)