mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
28.1k stars 2.88k forks source link

crash on mp_thread_join(vo->in->thread); objc_relase when using vulkan and gpu-next #14605

Closed miku1958 closed 2 months ago

miku1958 commented 2 months ago

mpv Information

mpv 6107112-dirty Copyright © 2000-2024 mpv/MPlayer/mplayer2 projects
 built on Jul 28 2024 21:26:02
libplacebo version: v7.349.0
FFmpeg version: 7.0.1
FFmpeg library versions:
   libavcodec      61.3.100
   libavdevice     61.1.100
   libavfilter     10.1.100
   libavformat     61.1.100
   libavutil       59.8.100
   libswresample   5.1.100
   libswscale      8.1.100

Other Information

Reproduction Steps

build mpv with molten-vk

enable gpu-next

play a Dolby Vision video

close the window

Expected Behavior

No crash happen

Actual Behavior

Crash

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Process:               mpv [38636]
Path:                  /Applications/mpv.app/Contents/MacOS/mpv
Identifier:            io.mpv
Version:               0.38.0-UNKNOWN (???)
Code Type:             ARM-64 (Native)
Parent Process:        launchd [1]
User ID:               501

Date/Time:             2024-07-28 22:33:15.3016 +0800
OS Version:            macOS 14.5 (23F79)
Report Version:        12
Anonymous UUID:        3CF821AC-783F-1D33-B7AE-95EE803BF66D

Sleep/Wake UUID:       F131ACB1-8403-43DF-BC82-533B2BFBCDD9

Time Awake Since Boot: 130000 seconds
Time Since Wake:       56031 seconds

System Integrity Protection: enabled

Crashed Thread:        8  vo

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000ea0080020
Exception Codes:       0x0000000000000001, 0x0000000ea0080020

Termination Reason:    Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process:   exc handler [38636]

VM Region Info: 0xea0080020 is not in any region.  Bytes after previous region: 47647817761  Bytes before following region: 4831313888
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      MALLOC_MEDIUM               380000000-388000000    [128.0M] rw-/rwx SM=PRV  
--->  GAP OF 0xc38000000 BYTES
      commpage (reserved)         fc0000000-1000000000   [  1.0G] ---/--- SM=NUL  reserved VM address space (unallocated)

Thread 6:: */playback
0   libsystem_kernel.dylib                 0x18620ffac __ulock_wait + 8
1   libsystem_pthread.dylib                0x18625148c _pthread_join + 608
2   mpv                                    0x104dfa078 vo_destroy + 56 (vo.c:374)
3   mpv                                    0x104dc0c7c uninit_video_out + 32 (video.c:132)
4   mpv                                    0x104db7cb0 mp_destroy + 52 (main.c:173)
5   mpv                                    0x104db8660 mpv_main + 308 (main.c:470)
6   mpv                                    0x104cfe6e8 closure #1 in variable initialization expression of Application.playbackThread + 76 (application.swift:98) [inlined]
7   mpv                                    0x104cfe6e8 @objc closure #1 in variable initialization expression of Application.playbackThread + 92 (/<compiler-generated>:95)
8   libsystem_pthread.dylib                0x18624ef94 _pthread_start + 136
9   libsystem_pthread.dylib                0x186249d34 thread_start + 8

Thread 8 Crashed:: vo
0   libobjc.A.dylib                        0x185e786b4 objc_release + 16
1   libobjc.A.dylib                        0x185e7fc90 AutoreleasePoolPage::releaseUntil(objc_object**) + 212
2   libobjc.A.dylib                        0x185e7c2fc objc_autoreleasePoolPop + 260
3   libobjc.A.dylib                        0x185eadaac objc_tls_direct_base<AutoreleasePoolPage*, (tls_key)3, AutoreleasePoolPage::HotPageDealloc>::dtor_(void*) + 168
4   libsystem_pthread.dylib                0x18624c8f4 _pthread_tsd_cleanup + 620
5   libsystem_pthread.dylib                0x18624f684 _pthread_exit + 84
6   libsystem_pthread.dylib                0x18624efa0 _pthread_start + 148
7   libsystem_pthread.dylib                0x186249d34 thread_start + 8

Log File

I do some debug and seem the release of vulkan is handled by the autoreleasepool, and waiting for this thread will result in an objc release error.

I tried the following modification to avoid the crash, but I'm not sure if it's the right fix:

#if HAVE_MACOS_COCOA_CB
#include "gpu/context.h"
extern const struct ra_ctx_fns ra_ctx_vulkan_mac;
#endif

void vo_destroy(struct vo *vo)
{
    struct vo_internal *in = vo->in;
    mp_dispatch_run(in->dispatch, terminate_vo, vo);
    mp_thread_join(vo->in->thread);
    if (vo->context_name != ra_ctx_vulkan_mac.name) {
        mp_thread_join(vo->in->thread);
    }
    dealloc_vo(vo);
}

Sample Files

No response

I carefully read all instruction and confirm that I did the following:

Akemi commented 2 months ago

duplicate of #12666