gui: macosx: Fix a window restoration conflict with qt contrib
requested to merge umxprime/vlc:4.x/gui/macos/fix-window-restore-conflict-with-qt-contrib into master
Given vlc was built with Qt contrib and launched on macOS with -Iqt
arg,
When Qt interface initialised, the macOS window restoration mechanism unexpectedly calls -[VLCLibraryWindowController restoreWindowWithIdentifier:state:completionHandler:]
with the wrong identifier.
Then this crash happened :
* thread #1, name = 'vlc-qt', queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x8)
frame #0: 0x00000001089a85fc libvlccore.dylib`vlc_object_parent(obj=0x0000000000000000) at objects.c:116:12
113
114 vlc_object_t *(vlc_object_parent)(vlc_object_t *obj)
115 {
-> 116 return vlc_internals(obj)->parent;
117 }
118
119 struct vlc_tracer *vlc_object_get_tracer(vlc_object_t *obj)
Target 0: (vlc-osx-static) stopped.
(lldb) thread backtrace
* thread #1, name = 'vlc-qt', queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x8)
* frame #0: 0x00000001089a85fc libvlccore.dylib`vlc_object_parent(obj=0x0000000000000000) at objects.c:116:12
frame #1: 0x00000001088fb57d libvlccore.dylib`vlc_object_instance(obj=0x0000000000000000) at vlc_objects.h:173:19
frame #2: 0x00000001088fb475 libvlccore.dylib`vlc_intf_GetMainPlaylist(intf=0x0000000000000000) at interface.c:119:49
frame #3: 0x000000012bdf651c libmacosx_plugin.dylib`-[VLCMain init](self=0x000060000376b180, _cmd="init") at VLCMain.m:215:79
frame #4: 0x000000012bdf633c libmacosx_plugin.dylib`__25+[VLCMain sharedInstance]_block_invoke(.block_descriptor=0x000000012bf58650) at VLCMain.m:185:26
frame #5: 0x00007ff813a7e317 libdispatch.dylib`_dispatch_client_callout + 8
frame #6: 0x00007ff813a7f4fa libdispatch.dylib`_dispatch_once_callout + 20
frame #7: 0x000000012bdf62ee libmacosx_plugin.dylib`+[VLCMain sharedInstance] [inlined] _dispatch_once(predicate=0x000000012bfa23a8, block=0x000000012bdf6320) at once.h:84:3
frame #8: 0x000000012bdf62d3 libmacosx_plugin.dylib`+[VLCMain sharedInstance](self=VLCMain, _cmd="sharedInstance") at VLCMain.m:184:5
frame #9: 0x000000012bdf4585 libmacosx_plugin.dylib`+[VLCLibraryWindowController restoreWindowWithIdentifier:state:completionHandler:](self=VLCLibraryWindowController, _cmd="restoreWindowWithIdentifier:state:completionHandler:", identifier=@"_NS:6", state=0x00006000002b81e0, completionHandler=0x00007ff816797cbe) at VLCLibraryWindow.m:977:8
frame #10: 0x00007ff81665f819 AppKit`-[NSApplication(NSPersistentUIRestorationSupport) restoreWindowWithIdentifier:state:completionHandler:] + 264
frame #11: 0x00007ff81665f3e4 AppKit`-[NSApplication(NSPersistentUIRestorationSupport) _restoreWindowWithRestoration:completionHandler:] + 530
frame #12: 0x00007ff81715977a AppKit`-[NSPersistentUIRestorer restoreStateFromRecords:usingDelegate:requireSecureCoding:completionHandler:] + 1789
frame #13: 0x00007ff81665e561 AppKit`-[NSPersistentUIManager restoreAllPersistentStateWithCompletionHandler:] + 303
frame #14: 0x00007ff81665d975 AppKit`-[NSApplication _reopenWindowsAsNecessaryIncludingRestorableState:completionHandler:] + 358
frame #15: 0x00007ff81665d6ff AppKit`-[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:] + 528
frame #16: 0x00007ff81665d360 AppKit`-[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] + 665
frame #17: 0x00007ff814a59834 Foundation`-[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 308
frame #18: 0x00007ff814a596a6 Foundation`_NSAppleEventManagerGenericHandler + 80
frame #19: 0x00007ff81a33a3f0 AE`___lldb_unnamed_symbol68$$AE + 1849
frame #20: 0x00007ff81a339c5a AE`___lldb_unnamed_symbol67$$AE + 34
frame #21: 0x00007ff81a33338f AE`aeProcessAppleEvent + 419
frame #22: 0x00007ff81ce013d2 HIToolbox`AEProcessAppleEvent + 54
frame #23: 0x00007ff816657992 AppKit`_DPSNextEvent + 2036
frame #24: 0x00007ff816655bfa AppKit`-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1394
frame #25: 0x00007ff8166482a9 AppKit`-[NSApplication run] + 586
frame #26: 0x00000001242e6b1a libqt_plugin.dylib`QCocoaEventDispatcher::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 2090
frame #27: 0x0000000124984be6 libqt_plugin.dylib`QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 502
frame #28: 0x0000000124988c52 libqt_plugin.dylib`QCoreApplication::exec() + 130
frame #29: 0x00000001232bc7c8 libqt_plugin.dylib`Thread(obj=0x0000600002c06780) at qt.cpp:864:5
frame #30: 0x00000001232bb741 libqt_plugin.dylib`OpenInternal(p_intf=0x0000600002c06780) at qt.cpp:519:5
frame #31: 0x00000001232bb4e2 libqt_plugin.dylib`OpenIntfCommon(p_this=0x000060000170d540, dialogProvider=false) at qt.cpp:589:15
frame #32: 0x00000001232b9db7 libqt_plugin.dylib`OpenIntf(p_this=0x000060000170d540) at qt.cpp:609:12
frame #33: 0x00000001088f286b libvlccore.dylib`generic_start(func=0x00000001232b9da0, forced=true, ap=0x00000003040c75e0) at modules.c:275:11
frame #34: 0x00000001088f259b libvlccore.dylib`vlc_module_load(log=0x0000600000004088, capability="interface", name="qt", strict=true, probe=(libvlccore.dylib`generic_start at modules.c:269)) at modules.c:243:19
frame #35: 0x00000001088f2780 libvlccore.dylib`module_need(obj=0x000060000170d540, cap="interface", name="qt", strict=true) at modules.c:286:24
frame #36: 0x00000001088fb801 libvlccore.dylib`intf_Create(libvlc=0x0000600003300000, chain="qt") at interface.c:172:24
frame #37: 0x00000001088fbc35 libvlccore.dylib`libvlc_InternalAddIntf(libvlc=0x0000600003300000, name=0x0000000000000000) at interface.c:277:15
frame #38: 0x0000000108694540 libvlc.dylib`libvlc_add_intf(p_instance=0x00006000026000c0, name=0x0000000000000000) at playlist.c:41:9
frame #39: 0x000000010000361a vlc-osx-static`main(i_argc=1, ppsz_argv=0x00000003040c79c8) at darwinvlc.m:276:9
frame #40: 0x000000020001551e dyld`start + 462
This patch is an attempt to fix it.