Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Freeze in PlayerCore.syncUI at the start of playback #3997

Open
1 task
low-batt opened this issue Oct 16, 2022 · 2 comments
Open
1 task

Freeze in PlayerCore.syncUI at the start of playback #3997

low-batt opened this issue Oct 16, 2022 · 2 comments

Comments

@low-batt
Copy link
Contributor

System and IINA version:

  • macOS 12.6
  • IINA 1.3.0

Expected behavior:
IINA does not hang.

Actual behavior:
I double clicked on a movie file, IINA started up and immediately froze. CPU was being consumed. UI would not respond. I had to force quit.

This is a thread race condition. VERY difficult to reproduce. Would need to develop some sort of test script that runs IINA over and over again until the problem reproduces.

Process Sample:
Sampling process 42788 for 3 seconds with 1 millisecond of run time between samples
Sampling completed, processing symbols...
Analysis of sampling IINA (pid 42788) every 1 millisecond
Process:         IINA [42788]
Path:            /Applications/IINA.app/Contents/MacOS/IINA
Load Address:    0x102b68000
Identifier:      com.colliderli.iina
Version:         1.3.0 (132)
Code Type:       ARM64
Platform:        macOS
Parent Process:  ??? [1]

Date/Time:       2022-10-15 14:04:36.873 -0400
Launch Time:     2022-10-15 14:03:39.781 -0400
OS Version:      macOS 12.6 (21G115)
Report Version:  7
Analysis Tool:   /usr/bin/sample

Physical footprint:         201.7M
Physical footprint (peak):  220.8M
----

Call graph:
    2100 Thread_9196968   DispatchQueue_1: com.apple.main-thread  (serial)
    + 2100 start  (in dyld) + 520  [0x10324508c]
    +   2100 main  (in IINA) + 12  [0x102b72b40]
    +     2100 NSApplicationMain  (in AppKit) + 1132  [0x1b62686fc]
    +       2100 -[NSApplication run]  (in AppKit) + 596  [0x1b6296fe0]
    +         2100 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]  (in AppKit) + 1328  [0x1b62a4e14]
    +           2100 _DPSNextEvent  (in AppKit) + 860  [0x1b62a651c]
    +             2100 _BlockUntilNextEventMatchingListInModeWithFilter  (in HIToolbox) + 72  [0x1bc37de68]
    +               2100 ReceiveNextEventCommon  (in HIToolbox) + 564  [0x1bc37e0b4]
    +                 2100 RunCurrentEventLoopInMode  (in HIToolbox) + 292  [0x1bc37e338]
    +                   2100 CFRunLoopRunSpecific  (in CoreFoundation) + 600  [0x1b373ea84]
    +                     2100 __CFRunLoopRun  (in CoreFoundation) + 1936  [0x1b373f9b4]
    +                       2100 __CFRunLoopDoTimers  (in CoreFoundation) + 392  [0x1b375af3c]
    +                         2100 __CFRunLoopDoTimer  (in CoreFoundation) + 1064  [0x1b375b4b4]
    +                           2100 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__  (in CoreFoundation) + 32  [0x1b375b8cc]
    +                             2100 __NSFireTimer  (in Foundation) + 104  [0x1b46668f0]
    +                               2100 @objc PlayerCore.syncUITime()  (in IINA) + 28  [0x102c9d860]
    +                                 2100 PlayerCore.syncUITime()  (in IINA) + 56  [0x102c9d76c]
    +                                   2100 PlayerCore.syncUI(_:)  (in IINA) + 560  [0x102c9daa0]
    +                                     2100 mpv_get_property  (in libmpv.1.dylib) + 92  [0x103b5d464]
    +                                       2100 mp_dispatch_lock  (in libmpv.1.dylib) + 188  [0x103b45c74]
    +                                         2100 _pthread_cond_wait  (in libsystem_pthread.dylib) + 1236  [0x1b367483c]
    +                                           2100 __psynch_cvwait  (in libsystem_kernel.dylib) + 8  [0x1b363a270]
    2100 Thread_9196987   DispatchQueue_167: com.colliderli.iina.controller  (serial)
    + 2100 start_wqthread  (in libsystem_pthread.dylib) + 8  [0x1b366f080]
    +   2100 _pthread_wqthread  (in libsystem_pthread.dylib) + 288  [0x1b3670360]
    +     2100 _dispatch_workloop_worker_thread  (in libdispatch.dylib) + 648  [0x1b34c2c98]
    +       2100 _dispatch_lane_invoke  (in libdispatch.dylib) + 392  [0x1b34b8404]
    +         2100 _dispatch_lane_serial_drain  (in libdispatch.dylib) + 668  [0x1b34b78a8]
    +           2100 _dispatch_client_callout  (in libdispatch.dylib) + 20  [0x1b34b01b4]
    +             2100 _dispatch_call_block_and_release  (in libdispatch.dylib) + 32  [0x1b34ae5f0]
    +               2100 thunk for @escaping @callee_guaranteed () -> ()  (in IINA) + 28  [0x102cbb038]
    +                 2100 partial apply for closure #1 in MPVController.readEvents()  (in IINA) + 32  [0x102cc6fd0]
    +                   2100 MPVController.handleEvent(_:)  (in IINA) + 2644  [0x102cc06a8]
    +                     2100 PlayerCore.playbackRestarted()  (in IINA) + 208  [0x102c9bf28]
    +                       2100 @objc ViewLayer.display()  (in IINA) + 60  [0x102c6253c]
    +                         2100 -[CAOpenGLLayer _display]  (in QuartzCore) + 584  [0x1ba6702c8]
    +                           2100 CAOpenGLLayerDraw(CAOpenGLLayer*, double, CVTimeStamp const*, unsigned int)  (in QuartzCore) + 1520  [0x1ba670aa4]
    +                             2100 @objc ViewLayer.draw(inCGLContext:pixelFormat:forLayerTime:displayTime:)  (in IINA) + 28  [0x102c621e8]
    +                               2100 specialized ViewLayer.draw(inCGLContext:pixelFormat:forLayerTime:displayTime:)  (in IINA) + 340  [0x102c63a88]
    +                                 2100 closure #1 in ViewLayer.draw(inCGLContext:pixelFormat:forLayerTime:displayTime:)  (in IINA) + 156  [0x102c6218c]
    +                                   2100 specialized closure #1 in closure #1 in ViewLayer.draw(inCGLContext:pixelFormat:forLayerTime:displayTime:)  (in IINA) + 144  [0x102c6391c]
    +                                     2100 mpv_render_context_render  (in libmpv.1.dylib) + 652  [0x103bc72f8]
    +                                       2100 render  (in libmpv.1.dylib) + 168  [0x103babb7c]
    +                                         2100 gl_video_render_frame  (in libmpv.1.dylib) + 1756  [0x103bb2a00]
    +                                           2100 pass_draw_osd  (in libmpv.1.dylib) + 100  [0x103bb5898]
    +                                             2100 mpgl_osd_generate  (in libmpv.1.dylib) + 220  [0x103bac2fc]
    +                                               2100 osd_draw  (in libmpv.1.dylib) + 52  [0x103b90c88]
    +                                                 2100 osd_render  (in libmpv.1.dylib) + 568  [0x103b90af0]
    +                                                   2100 sub_get_bitmaps  (in libmpv.1.dylib) + 44  [0x103b8b5c8]
    +                                                     2100 _pthread_mutex_firstfit_lock_slow  (in libsystem_pthread.dylib) + 248  [0x1b366ecf8]
    +                                                       2100 _pthread_mutex_firstfit_lock_wait  (in libsystem_pthread.dylib) + 84  [0x1b3671384]
    +                                                         2100 __psynch_mutexwait  (in libsystem_kernel.dylib) + 8  [0x1b3639738]
    2100 Thread_9197009: mpv/mpv core
    + 2100 thread_start  (in libsystem_pthread.dylib) + 8  [0x1b366f08c]
    +   2100 _pthread_start  (in libsystem_pthread.dylib) + 148  [0x1b367426c]
    +     2100 core_thread  (in libmpv.1.dylib) + 72  [0x103b5bf1c]
    +       2100 mp_play_files  (in libmpv.1.dylib) + 6628  [0x103b75c4c]
    +         2100 run_playloop  (in libmpv.1.dylib) + 140  [0x103b7e554]
    +           2100 write_video  (in libmpv.1.dylib) + 2500  [0x103b82e0c]
    +             2100 update_subtitles  (in libmpv.1.dylib) + 256  [0x103b819b0]
    +               2100 sub_preload  (in libmpv.1.dylib) + 104  [0x103b8b1f8]
    +                 1862 demux_read_packet_async_until  (in libmpv.1.dylib) + 116  [0x103b14830]
    +                 ! 1697 thread_work  (in libmpv.1.dylib) + 1692  [0x103b152dc]
    +                 ! : 1660 mp_time_us  (in libmpv.1.dylib) + 12  [0x103bcfdd0]
    +                 ! : | 1660 mp_raw_time_us  (in libmpv.1.dylib) + 12  [0x103bd0130]
    +                 ! : |   1617 mach_absolute_time  (in libsystem_kernel.dylib) + 108,112  [0x1b3636f0c,0x1b3636f10]
    +                 ! : |   43 DYLD-STUB$$mach_absolute_time  (in libmpv.1.dylib) + 0  [0x103be3d78]
    +                 ! : 37 mp_time_us  (in libmpv.1.dylib) + 12  [0x103bcfdd0]
    +                 ! 97 thread_work  (in libmpv.1.dylib) + 48  [0x103b14c70]
    +                 ! : 59 m_config_cache_update  (in libmpv.1.dylib) + 148,4  [0x103b48958,0x103b488c8]
    +                 ! : 37 thread_work  (in libmpv.1.dylib) + 524  [0x103b14e4c]
    +                 ! : 1 thread_work  (in libmpv.1.dylib) + 48  [0x103b14c70]
    +                 ! :   1 m_config_cache_update  (in libmpv.1.dylib) + 32  [0x103b488e4]
    +                 ! 68 thread_work  (in libmpv.1.dylib) + 8,392  [0x103b14c48,0x103b14dc8]
    +                 238 demux_read_packet_async_until  (in libmpv.1.dylib) + 80  [0x103b1480c]
    +                   116 dequeue_packet  (in libmpv.1.dylib) + 156  [0x103b14900]
    +                   : 54 dequeue_packet  (in libmpv.1.dylib) + 156  [0x103b14900]
    +                   : | 54 pthread_cond_signal  (in libsystem_pthread.dylib) + 88,752  [0x1b367324c,0x1b36734e4]
    +                   : 37 dequeue_packet  (in libmpv.1.dylib) + 224  [0x103b14944]
    +                   : 25 pthread_cond_signal  (in libsystem_pthread.dylib) + 8  [0x1b36731fc]
    +                   77 dequeue_packet  (in libmpv.1.dylib) + 4,96  [0x103b14868,0x103b148c4]
    +                   45 demux_read_packet_async_until  (in libmpv.1.dylib) + 80  [0x103b1480c]
    +                     45 dequeue_packet  (in libmpv.1.dylib) + 60  [0x103b148a0]
    2100 Thread_9197054   DispatchQueue_536: com.colliderli.iina.mpvgl  (serial)
    + 2100 start_wqthread  (in libsystem_pthread.dylib) + 8  [0x1b366f080]
    +   2100 _pthread_wqthread  (in libsystem_pthread.dylib) + 288  [0x1b3670360]
    +     2100 _dispatch_workloop_worker_thread  (in libdispatch.dylib) + 648  [0x1b34c2c98]
    +       2100 _dispatch_lane_invoke  (in libdispatch.dylib) + 392  [0x1b34b8404]
    +         2100 _dispatch_lane_serial_drain  (in libdispatch.dylib) + 668  [0x1b34b78a8]
    +           2100 _dispatch_client_callout  (in libdispatch.dylib) + 20  [0x1b34b01b4]
    +             2100 _dispatch_call_block_and_release  (in libdispatch.dylib) + 32  [0x1b34ae5f0]
    +               2100 thunk for @escaping @callee_guaranteed () -> ()  (in IINA) + 28  [0x102cbb038]
    +                 2100 partial apply for closure #1 in mpvUpdateCallback(_:)  (in IINA) + 24  [0x102cc866c]
    +                   2100 ViewLayer.draw(forced:)  (in IINA) + 244  [0x102c622ec]
    +                     2100 CGLLockContext  (in OpenGL) + 40  [0x214dfa51c]
    +                       2100 _pthread_mutex_firstfit_lock_slow  (in libsystem_pthread.dylib) + 248  [0x1b366ecf8]
    +                         2100 _pthread_mutex_firstfit_lock_wait  (in libsystem_pthread.dylib) + 84  [0x1b3671384]
    +                           2100 __psynch_mutexwait  (in libsystem_kernel.dylib) + 8  [0x1b3639738]
    2100 Thread_9197449: CVDisplayLink
    + 2100 thread_start  (in libsystem_pthread.dylib) + 8  [0x1b366f08c]
    +   2100 _pthread_start  (in libsystem_pthread.dylib) + 148  [0x1b367426c]
    +     2100 CVDisplayLink::runIOThread()  (in CoreVideo) + 488  [0x1bad1e460]
    +       2100 CVDisplayLink::waitUntil(unsigned long long)  (in CoreVideo) + 324  [0x1bad1f380]
    +         2100 _pthread_cond_wait  (in libsystem_pthread.dylib) + 1280  [0x1b3674868]
    +           2100 __psynch_cvwait  (in libsystem_kernel.dylib) + 8  [0x1b363a270]
    2100 Thread_9197456: mpv/worker
    + 2100 thread_start  (in libsystem_pthread.dylib) + 8  [0x1b366f08c]
    +   2100 _pthread_start  (in libsystem_pthread.dylib) + 148  [0x1b367426c]
    +     2100 worker_thread  (in libmpv.1.dylib) + 80  [0x103b474e8]
    +       2100 _pthread_cond_wait  (in libsystem_pthread.dylib) + 1236  [0x1b367483c]
    +         2100 __psynch_cvwait  (in libsystem_kernel.dylib) + 8  [0x1b363a270]
    2100 Thread_9197457: mpv/vo
    + 2100 thread_start  (in libsystem_pthread.dylib) + 8  [0x1b366f08c]
    +   2100 _pthread_start  (in libsystem_pthread.dylib) + 148  [0x1b367426c]
    +     2100 vo_thread  (in libmpv.1.dylib) + 1008  [0x103bc5268]
    +       2100 _pthread_cond_wait  (in libsystem_pthread.dylib) + 1236  [0x1b367483c]
    +         2100 __psynch_cvwait  (in libsystem_kernel.dylib) + 8  [0x1b363a270]
    2100 Thread_9197481: com.apple.audio.IOThread.client
    + 2100 thread_start  (in libsystem_pthread.dylib) + 8  [0x1b366f08c]
    +   2100 _pthread_start  (in libsystem_pthread.dylib) + 148  [0x1b367426c]
    +     2100 HALB_IOThread::Entry(void*)  (in CoreAudio) + 88  [0x1b53deab0]
    +       2100 invocation function for block in HALC_ProxyIOContext::HALC_ProxyIOContext(unsigned int, unsigned int)  (in CoreAudio) + 100  [0x1b52128b0]
    +         2097 HALC_ProxyIOContext::IOWorkLoop()  (in CoreAudio) + 3336  [0x1b5213bb0]
    +         ! 2097 HALB_MachPort::SendSimpleMessageWithSimpleReply(unsigned int, unsigned int, int, int&, bool, unsigned int)  (in CoreAudio) + 104  [0x1b53866a0]
    +         !   2097 mach_msg  (in libsystem_kernel.dylib) + 76  [0x1b3636d20]
    +         !     2097 mach_msg_trap  (in libsystem_kernel.dylib) + 8  [0x1b36368b0]
    +         3 HALC_ProxyIOContext::IOWorkLoop()  (in CoreAudio) + 6312  [0x1b5214750]
    +           3 ???  (in CoreAudio)  load address 0x117a94000 + 0xd2b0  [0x117aa12b0]
    +             3 ???  (in CoreAudio)  load address 0x117a94000 + 0x1050d8  [0x117b990d8]
    +               3 ???  (in CoreAudio)  load address 0x117a94000 + 0x8db4  [0x117a9cdb4]
    +                 1 ???  (in CoreAudio)  load address 0x117a94000 + 0x8e84  [0x117a9ce84]
    +                 1 acv1::_AudioConverterFillComplexBuffer(OpaqueAudioConverter*, int (*)(OpaqueAudioConverter*, unsigned int*, AudioBufferList*, AudioStreamPacketDescription**, void*), void*, unsigned int*, AudioBufferList*, AudioStreamPacketDescription*, AudioStreamPacketDependencyInfo*)  (in AudioToolboxCore) + 820  [0x1b4db7870]
    +                 : 1 acv1::BufferedAudioConverter::FillBuffer(unsigned int&, AudioBufferList&, AudioStreamPacketDescription*)  (in AudioToolboxCore) + 416  [0x1b4d807e8]
    +                 :   1 acv1::AudioConverterChain::RenderOutput(CADeprecated::CABufferList*, unsigned int, unsigned int&, AudioStreamPacketDescription*)  (in AudioToolboxCore) + 148  [0x1b4c26590]
    +                 :     1 acv1::BufferedAudioConverter::FillBuffer(unsigned int&, AudioBufferList&, AudioStreamPacketDescription*)  (in AudioToolboxCore) + 416  [0x1b4d807e8]
    +                 :       1 acv1::CBRConverter::RenderOutput(CADeprecated::CABufferList*, unsigned int, unsigned int&, AudioStreamPacketDescription*)  (in AudioToolboxCore) + 148  [0x1b4c0e2d0]
    +                 :         1 acv1::BufferedAudioConverter::GetInputBytes(unsigned int, unsigned int&, CADeprecated::CABufferList const*&)  (in AudioToolboxCore) + 220  [0x1b4d805ac]
    +                 :           1 acv1::AudioConverterChain::FillBufferFromInputProc(unsigned int*, CADeprecated::CABufferList*)  (in AudioToolboxCore) + 428  [0x1b4c295dc]
    +                 :             1 acv1::AudioConverterChain::CallInputProc(unsigned int)  (in AudioToolboxCore) + 436  [0x1b4c2615c]
    +                 :               1 ???  (in CoreAudio)  load address 0x117a94000 + 0x9398  [0x117a9d398]
    +                 :                 1 ???  (in CoreAudio)  load address 0x117a94000 + 0x105e0c  [0x117b99e0c]
    +                 :                   1 render_cb_lpcm  (in libmpv.1.dylib) + 288  [0x103b03ed0]
    +                 :                     1 ao_read_data  (in libmpv.1.dylib) + 88  [0x103b08194]
    +                 :                       1 read_buffer  (in libmpv.1.dylib) + 404  [0x103b08384]
    +                 :                         1 af_fill_silence  (in libmpv.1.dylib) + 36  [0x103b01370]
    +                 :                           1 _platform_memset  (in libsystem_platform.dylib) + 140  [0x1b368ae8c]
    +                 1 acv1::_AudioConverterFillComplexBuffer(OpaqueAudioConverter*, int (*)(OpaqueAudioConverter*, unsigned int*, AudioBufferList*, AudioStreamPacketDescription**, void*), void*, unsigned int*, AudioBufferList*, AudioStreamPacketDescription*, AudioStreamPacketDependencyInfo*)  (in AudioToolboxCore) + 1056  [0x1b4db795c]
    +                   1 DYLD-STUB$$CrashIfClientProvidedBogusAudioBufferList  (in AudioToolboxCore) + 0  [0x1b4e0d1a8]
    2100 Thread_9197495: mpv/demux
    + 2100 thread_start  (in libsystem_pthread.dylib) + 8  [0x1b366f08c]
    +   2100 _pthread_start  (in libsystem_pthread.dylib) + 148  [0x1b367426c]
    +     2100 demux_thread  (in libmpv.1.dylib) + 236  [0x103b14050]
    +       2100 _pthread_cond_wait  (in libsystem_pthread.dylib) + 1236  [0x1b367483c]
    +         2100 __psynch_cvwait  (in libsystem_kernel.dylib) + 8  [0x1b363a270]

Truncated to meet GitHub limits...

Steps to reproduce:
All I did was double click on a movie file (IINA is set as the default app for .MP4).

This seems to be a thread race condition, so hard to reproduce.

  • MPV does not have this problem.

I do not know if this is reproducible with mpv.

How often does this happen?
Rarely.

@low-batt
Copy link
Contributor Author

Analysis

The main thread is blocked in PlayerCore.syncUI on a lock in mpv:

Main Thread
    +                                   2100 PlayerCore.syncUI(_:)  (in IINA) + 560  [0x102c9daa0]
    +                                     2100 mpv_get_property  (in libmpv.1.dylib) + 92  [0x103b5d464]
    +                                       2100 mp_dispatch_lock  (in libmpv.1.dylib) + 188  [0x103b45c74]
    +                                         2100 _pthread_cond_wait  (in libsystem_pthread.dylib) + 1236  [0x1b367483c]
    +                                           2100 __psynch_cvwait  (in libsystem_kernel.dylib) + 8  [0x1b363a270]

The thread for the dispatch queue com.colliderli.iina.controller is attempting to draw in response to an event from mpv:

com.colliderli.iina.controller
    +                   2100 MPVController.handleEvent(_:)  (in IINA) + 2644  [0x102cc06a8]
    +                     2100 PlayerCore.playbackRestarted()  (in IINA) + 208  [0x102c9bf28]
    +                       2100 @objc ViewLayer.display()  (in IINA) + 60  [0x102c6253c]
    +                         2100 -[CAOpenGLLayer _display]  (in QuartzCore) + 584  [0x1ba6702c8]
    +                           2100 CAOpenGLLayerDraw(CAOpenGLLayer*, double, CVTimeStamp const*, unsigned int)  (in QuartzCore) + 1520  [0x1ba670aa4]
    +                             2100 @objc ViewLayer.draw(inCGLContext:pixelFormat:forLayerTime:displayTime:)  (in IINA) + 28  [0x102c621e8]
    +                               2100 specialized ViewLayer.draw(inCGLContext:pixelFormat:forLayerTime:displayTime:)  (in IINA) + 340  [0x102c63a88]
    +                                 2100 closure #1 in ViewLayer.draw(inCGLContext:pixelFormat:forLayerTime:displayTime:)  (in IINA) + 156  [0x102c6218c]
    +                                   2100 specialized closure #1 in closure #1 in ViewLayer.draw(inCGLContext:pixelFormat:forLayerTime:displayTime:)  (in IINA) + 144  [0x102c6391c]
    +                                     2100 mpv_render_context_render  (in libmpv.1.dylib) + 652  [0x103bc72f8]
    +                                       2100 render  (in libmpv.1.dylib) + 168  [0x103babb7c]
    +                                         2100 gl_video_render_frame  (in libmpv.1.dylib) + 1756  [0x103bb2a00]
    +                                           2100 pass_draw_osd  (in libmpv.1.dylib) + 100  [0x103bb5898]
    +                                             2100 mpgl_osd_generate  (in libmpv.1.dylib) + 220  [0x103bac2fc]
    +                                               2100 osd_draw  (in libmpv.1.dylib) + 52  [0x103b90c88]
    +                                                 2100 osd_render  (in libmpv.1.dylib) + 568  [0x103b90af0]
    +                                                   2100 sub_get_bitmaps  (in libmpv.1.dylib) + 44  [0x103b8b5c8]
    +                                                     2100 _pthread_mutex_firstfit_lock_slow  (in libsystem_pthread.dylib) + 248  [0x1b366ecf8]
    +                                                       2100 _pthread_mutex_firstfit_lock_wait  (in libsystem_pthread.dylib) + 84  [0x1b3671384]
    +                                                         2100 __psynch_mutexwait  (in libsystem_kernel.dylib) + 8  [0x1b3639738]

The thread for the dispatch queue com.colliderli.iina.mpvgl is attempting to draw in response to the callback from mpv:

com.colliderli.iina.mpvgl
    +                 2100 partial apply for closure #1 in mpvUpdateCallback(_:)  (in IINA) + 24  [0x102cc866c]
    +                   2100 ViewLayer.draw(forced:)  (in IINA) + 244  [0x102c622ec]
    +                     2100 CGLLockContext  (in OpenGL) + 40  [0x214dfa51c]
    +                       2100 _pthread_mutex_firstfit_lock_slow  (in libsystem_pthread.dylib) + 248  [0x1b366ecf8]
    +                         2100 _pthread_mutex_firstfit_lock_wait  (in libsystem_pthread.dylib) + 84  [0x1b3671384]
    +                           2100 __psynch_mutexwait  (in libsystem_kernel.dylib) + 8  [0x1b3639738]

The mpv core thread is updating subtitles:

mpv/mpv core
    +       2100 mp_play_files  (in libmpv.1.dylib) + 6628  [0x103b75c4c]
    +         2100 run_playloop  (in libmpv.1.dylib) + 140  [0x103b7e554]
    +           2100 write_video  (in libmpv.1.dylib) + 2500  [0x103b82e0c]
    +             2100 update_subtitles  (in libmpv.1.dylib) + 256  [0x103b819b0]
    +               2100 sub_preload  (in libmpv.1.dylib) + 104  [0x103b8b1f8]
    +                 1862 demux_read_packet_async_until  (in libmpv.1.dylib) + 116  [0x103b14830]

It is expected that the thread for the dispatch queue com.colliderli.iina.mpvgl would be blocked on the OpenGL context lock because the thread for the dispatch queue com.colliderli.iina.controller is in the middle of drawing and has claimed that lock.

That drawing is happening from threads not belonging to the com.colliderli.iina.mpvgl queue is causing data races. This is reported in issue #3827. There is a fix pending in PR #3979.

Not clear how using the wrong thread for drawing would cause this problem. So there might be something else going on. Data races can cause odd problems. Need to fix all of them and see if this problem still reproduces.

@krackers
Copy link
Contributor

This one is interesting, at least looking at the stack traces it doesn't seem like a deadlock would be in progress.

sub_preload holds a lock on subtitle context as it calls into the demux thread to get packets. But unless demux thread was busy doing something else it should return fairly quickly (demux thread is not included in sample trace, so I cannot tell). Also demuxing alone shouldn't cause any direct-rendering callback, so I would have expected that shortly afterwards update_subtitles will finish, which will release the subtitle lock and allow osd_render in the controller thread to finish, which will release the CGL lock and allow draw in mpvgl to finish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants