From 26d78f646238ea39db9e997387382f2e7601d18a Mon Sep 17 00:00:00 2001 From: Nick Korotysh Date: Fri, 1 Jul 2022 23:09:37 +0200 Subject: [PATCH] Open destination folders on macOS in separate thread In some unknown way, the one line in Objective-C affects Qt's main loop causing the crash in QApplication::exec() on processing next event after that call. Even crash doesn't happen exactly after this call, it will happen on application exit. Call stack and disassembly are the same in all cases. But running that code in another thread solves the issue. Original PR: #17305. --- src/gui/macutilities.mm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/gui/macutilities.mm b/src/gui/macutilities.mm index 60e71cef0..c5b18181c 100644 --- a/src/gui/macutilities.mm +++ b/src/gui/macutilities.mm @@ -104,7 +104,15 @@ namespace MacUtils for (const auto &path : pathsList) [pathURLs addObject:[NSURL fileURLWithPath:path.toNSString()]]; - [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:pathURLs]; + // In some unknown way, the next line affects Qt's main loop causing the crash + // in QApplication::exec() on processing next event after this call. + // Even crash doesn't happen exactly after this call, it will happen on + // application exit. Call stack and disassembly are the same in all cases. + // But running it in another thread (aka in background) solves the issue. + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ + { + [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:pathURLs]; + }); } }