Closed low-batt closed 1 year ago
I removed the memset
statement, it is unnecessary. But I don't think that will fix the crash, since we use the exact range to clear up the array using two for loops after the memset anyway. Have you met this crash multiple times? Or just one time?
So far I have only seen this particular crash the one time. I have been doing stress testing starting and quitting IINA over and over again using a bash script. Mostly IINA is stable, but rarely this testing will generate a crash. This one is from that testing.
We still have thread data races that need to be addressed. That can cause random behavior. And of course this test is also stress testing mpv.
Once we have upgraded dependencies I will repeat this stress testing and see where we are at.
The bug here is that dist
has overflowed the stack.
System and IINA version:
Expected behavior: IINA does not crash.
Actual behavior: The
IINAPlayerCoreTask
thread crashed inObjcUtils.levDistance
called from theforceMatchUnmatchedVideos
method inAutoFileMatcher
at line 299:Crash report:
```text ------------------------------------- Translated Report (Full Report Below) ------------------------------------- Process: IINA [8516] Path: /Users/USER/Library/Developer/Xcode/DerivedData/iina-gwhhvjgxybcchtdcwvmukizbfeip/Build/Products/Debug/IINA.app/Contents/MacOS/IINA Identifier: com.colliderli.iina Version: 1.3.1 (133) Code Type: ARM-64 (Native) Parent Process: launchd [1] User ID: 503 Date/Time: 2023-04-01 16:25:04.3932 -0400 OS Version: macOS 13.3 (22E252) Report Version: 12 Anonymous UUID: C8F97525-3322-572C-B9CE-A91EB243AC3C Sleep/Wake UUID: 2D072A3C-8B2A-4071-A6BE-46BB0F1B403F Time Awake Since Boot: 61000 seconds Time Since Wake: 335 seconds System Integrity Protection: enabled Crashed Thread: 7 Dispatch queue: IINAPlayerCoreTask Exception Type: EXC_BAD_ACCESS (SIGBUS) Exception Codes: KERN_PROTECTION_FAILURE at 0x000000016b8b4000 Exception Codes: 0x0000000000000002, 0x000000016b8b4000 Termination Reason: Namespace SIGNAL, Code 10 Bus error: 10 Terminating Process: exc handler [8516] VM Region Info: 0x16b8b4000 is in 0x16b8b4000-0x16b8b8000; bytes after start: 0 bytes before end: 16383 REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL Stack 16b82c000-16b8b4000 [ 544K] rw-/rwx SM=PRV thread 7 ---> Stack Guard 16b8b4000-16b8b8000 [ 16K] ---/rwx SM=NUL Stack 16b8b8000-16b940000 [ 544K] rw-/rwx SM=PRV Thread 0:: Dispatch queue: com.apple.main-thread 0 libsystem_kernel.dylib 0x184c4bf14 mach_msg2_trap + 8 1 libsystem_kernel.dylib 0x184c5e240 mach_msg2_internal + 80 2 libsystem_kernel.dylib 0x184c54b78 mach_msg_overwrite + 604 3 libsystem_kernel.dylib 0x184c4c290 mach_msg + 24 4 CoreFoundation 0x184d6a8b8 __CFRunLoopServiceMachPort + 160 5 CoreFoundation 0x184d69198 __CFRunLoopRun + 1208 6 CoreFoundation 0x184d6858c CFRunLoopRunSpecific + 612 7 HIToolbox 0x18e59ddf4 RunCurrentEventLoopInMode + 292 8 HIToolbox 0x18e59dc30 ReceiveNextEventCommon + 648 9 HIToolbox 0x18e59d988 _BlockUntilNextEventMatchingListInModeWithFilter + 76 10 AppKit 0x187f87f58 _DPSNextEvent + 636 11 AppKit 0x187f870f4 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 716 12 AppKit 0x187f7b558 -[NSApplication run] + 464 13 AppKit 0x187f529a8 NSApplicationMain + 880 14 IINA 0x104ab9a30 main + 12 (AppDelegate.swift:24) 15 dyld 0x184933f28 start + 2236 Thread 1: 0 libsystem_pthread.dylib 0x184c86d8c start_wqthread + 0 Thread 2:: Dispatch queue: IINAHistoryController 0 CoreFoundation 0x184d10ef8 CFDictionaryAddValue + 12 1 CoreFoundation 0x184d407e8 _flattenPlist + 308 2 CoreFoundation 0x184d4094c _flattenPlist + 664 3 CoreFoundation 0x184d409b0 _flattenPlist + 764 4 CoreFoundation 0x184d4094c _flattenPlist + 664 5 CoreFoundation 0x184d400f0 __CFBinaryPlistWriteOrPresize + 320 6 Foundation 0x185ccf148 -[NSKeyedArchiver finishEncoding] + 636 7 Foundation 0x185d90404 +[NSKeyedArchiver archiveRootObject:toFile:] + 224 8 IINA 0x104af11e0 HistoryController.save() + 420 (HistoryController.swift:31) 9 IINA 0x104af17c8 HistoryController.add(_:duration:) + 1180 (HistoryController.swift:44) 10 IINA 0x104caec88 closure #2 in PlayerCore.fileLoaded() + 116 (PlayerCore.swift:1458) 11 IINA 0x1048c0a50 thunk for @escaping @callee_guaranteed () -> () + 48 12 libdispatch.dylib 0x184ada874 _dispatch_call_block_and_release + 32 13 libdispatch.dylib 0x184adc400 _dispatch_client_callout + 20 14 libdispatch.dylib 0x184ae3a88 _dispatch_lane_serial_drain + 668 15 libdispatch.dylib 0x184ae45f8 _dispatch_lane_invoke + 384 16 libdispatch.dylib 0x184aef244 _dispatch_workloop_worker_thread + 648 17 libsystem_pthread.dylib 0x184c88074 _pthread_wqthread + 288 18 libsystem_pthread.dylib 0x184c86d94 start_wqthread + 8 Thread 3: 0 libsystem_pthread.dylib 0x184c86d8c start_wqthread + 0 Thread 4: 0 libsystem_pthread.dylib 0x184c86d8c start_wqthread + 0 Thread 5: 0 libsystem_pthread.dylib 0x184c86d8c start_wqthread + 0 Thread 6: 0 libsystem_pthread.dylib 0x184c86d8c start_wqthread + 0 Thread 7 Crashed:: Dispatch queue: IINAPlayerCoreTask 0 libsystem_platform.dylib 0x184cba474 _platform_memset + 164 1 IINA 0x10489977c +[ObjcUtils levDistance:and:] + 388 (ObjcUtils.m:60) 2 IINA 0x1049ac180 AutoFileMatcher.forceMatchUnmatchedVideos() + 2552 (AutoFileMatcher.swift:299) 3 IINA 0x1049ae2c8 AutoFileMatcher.startMatching() + 4124 (AutoFileMatcher.swift:359) 4 IINA 0x104cb0da0 PlayerCore.autoLoadFilesInCurrentFolder(ticket:) + 92 (PlayerCore.swift:1551) 5 IINA 0x104cac75c closure #3 in PlayerCore.fileStarted(path:) + 488 (PlayerCore.swift:1391) 6 IINA 0x1048c0a50 thunk for @escaping @callee_guaranteed () -> () + 48 7 libdispatch.dylib 0x184ada874 _dispatch_call_block_and_release + 32 8 libdispatch.dylib 0x184adc400 _dispatch_client_callout + 20 9 libdispatch.dylib 0x184ae3a88 _dispatch_lane_serial_drain + 668 10 libdispatch.dylib 0x184ae45f8 _dispatch_lane_invoke + 384 11 libdispatch.dylib 0x184aef244 _dispatch_workloop_worker_thread + 648 12 libsystem_pthread.dylib 0x184c88074 _pthread_wqthread + 288 13 libsystem_pthread.dylib 0x184c86d94 start_wqthread + 8 Thread 8:: Dispatch queue: com.colliderli.iina.controller 0 libsystem_kernel.dylib 0x184c4ebc8 __psynch_mutexwait + 8 1 libsystem_pthread.dylib 0x184c890c4 _pthread_mutex_firstfit_lock_wait + 84 2 libsystem_pthread.dylib 0x184c86a5c _pthread_mutex_firstfit_lock_slow + 248 3 libsystem_pthread.dylib 0x184c8c600 _pthread_cond_wait + 1372 4 CoreAudio 0x1872c5150 HALB_Guard::WaitFor(unsigned long long) + 232 5 CoreAudio 0x1870c443c HALB_IOThread::_WaitForState(unsigned int) + 272 6 CoreAudio 0x1870c491c HALB_IOThread::StartAndWaitForState(unsigned int) + 516 7 CoreAudio 0x186f66314 HALC_ProxyIOContext::_StartIO() + 300 8 CoreAudio 0x186f2cef8 HAL_HardwarePlugIn_DeviceStart(AudioHardwarePlugInInterface**, unsigned int, int (*)(unsigned int, AudioTimeStamp const*, AudioBufferList const*, AudioTimeStamp const*, AudioBufferList*, AudioTimeStamp const*, void*)) + 1012 9 CoreAudio 0x186d8fe9c AudioDeviceStart + 248 10 CoreAudio 0x12f9d4aa4 0x12f9c8000 + 51876 11 CoreAudio 0x12f9d4888 0x12f9c8000 + 51336 12 CoreAudio 0x12fad1da8 0x12f9c8000 + 1088936 13 AudioToolboxCore 0x186af7fe4 AudioOutputUnitStart + 316 14 libmpv.1.dylib 0x106093aec start + 28 15 libmpv.1.dylib 0x106098b38 ao_set_paused + 280 16 libmpv.1.dylib 0x10610cf34 set_pause_state + 88 17 libmpv.1.dylib 0x1060f39dc mp_option_change_callback + 616 18 libmpv.1.dylib 0x1060da448 m_config_set_option_raw + 356 19 libmpv.1.dylib 0x1060f350c mp_property_generic_option + 160 20 libmpv.1.dylib 0x1060e68b0 m_property_do + 4284 21 libmpv.1.dylib 0x1060ef7b8 mp_property_do + 76 22 libmpv.1.dylib 0x1060ed1bc setproperty_fn + 116 23 libmpv.1.dylib 0x1060ed0d8 mpv_set_property + 92 24 IINA 0x104cf2650 MPVController.setFlag(_:_:) + 600 (MPVController.swift:538) 25 IINA 0x104cfd128 MPVController.onFileLoaded() + 1700 (MPVController.swift:981) 26 IINA 0x104cfa818 MPVController.handleEvent(_:) + 7192 (MPVController.swift:869) 27 IINA 0x104cf89b4 closure #1 in MPVController.readEvents() + 520 (MPVController.swift:776) 28 IINA 0x1048c0a50 thunk for @escaping @callee_guaranteed () -> () + 48 29 libdispatch.dylib 0x184ada874 _dispatch_call_block_and_release + 32 30 libdispatch.dylib 0x184adc400 _dispatch_client_callout + 20 31 libdispatch.dylib 0x184ae3a88 _dispatch_lane_serial_drain + 668 32 libdispatch.dylib 0x184ae45f8 _dispatch_lane_invoke + 384 33 libdispatch.dylib 0x184aef244 _dispatch_workloop_worker_thread + 648 34 libsystem_pthread.dylib 0x184c88074 _pthread_wqthread + 288 35 libsystem_pthread.dylib 0x184c86d94 start_wqthread + 8 Thread 9: 0 libsystem_pthread.dylib 0x184c86d8c start_wqthread + 0 Thread 10: 0 libsystem_pthread.dylib 0x184c86d8c start_wqthread + 0 Thread 11:: */mpv core 0 libsystem_kernel.dylib 0x184c4f710 __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x184c8c574 _pthread_cond_wait + 1232 2 libmpv.1.dylib 0x1060d5a34 mp_dispatch_queue_process + 140 3 libmpv.1.dylib 0x10610cca8 mp_wait_events + 80 4 libmpv.1.dylib 0x10610edf0 run_playloop + 2344 5 libmpv.1.dylib 0x106105c4c mp_play_files + 6628 6 libmpv.1.dylib 0x1060ebf1c core_thread + 72 7 libsystem_pthread.dylib 0x184c8bfa8 _pthread_start + 148 8 libsystem_pthread.dylib 0x184c86da0 thread_start + 8 Thread 12:: */log-file 0 libsystem_kernel.dylib 0x184c4f710 __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x184c8c574 _pthread_cond_wait + 1232 2 libmpv.1.dylib 0x10609eb38 log_file_thread + 120 3 libsystem_pthread.dylib 0x184c8bfa8 _pthread_start + 148 4 libsystem_pthread.dylib 0x184c86da0 thread_start + 8 Thread 13:: */lua script (ytdl_hook) 0 libsystem_kernel.dylib 0x184c4f710 __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x184c8c574 _pthread_cond_wait + 1232 2 libmpv.1.dylib 0x1060eb7b4 wait_wakeup + 88 3 libmpv.1.dylib 0x1060ec11c mpv_wait_event + 420 4 libmpv.1.dylib 0x106107970 script_raw_wait_event + 120 5 libluajit-5.1.2.dylib 0x10650a838 lj_BC_FUNCC + 44 6 libluajit-5.1.2.dylib 0x106517490 lua_pcall + 148 7 libluajit-5.1.2.dylib 0x10650a838 lj_BC_FUNCC + 44 8 libmpv.1.dylib 0x106107444 load_scripts + 376 9 libluajit-5.1.2.dylib 0x10650a838 lj_BC_FUNCC + 44 10 libluajit-5.1.2.dylib 0x106517490 lua_pcall + 148 11 libluajit-5.1.2.dylib 0x10650a838 lj_BC_FUNCC + 44 12 libluajit-5.1.2.dylib 0x1065174d0 lua_cpcall + 28 13 libmpv.1.dylib 0x1061116a4 run_script + 100 14 libmpv.1.dylib 0x106111728 script_thread + 32 15 libsystem_pthread.dylib 0x184c8bfa8 _pthread_start + 148 16 libsystem_pthread.dylib 0x184c86da0 thread_start + 8 Thread 14:: */lua script (stats) 0 libsystem_kernel.dylib 0x184c4f710 __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x184c8c574 _pthread_cond_wait + 1232 2 libmpv.1.dylib 0x1060eb7b4 wait_wakeup + 88 3 libmpv.1.dylib 0x1060ec11c mpv_wait_event + 420 4 libmpv.1.dylib 0x106107970 script_raw_wait_event + 120 5 libluajit-5.1.2.dylib 0x10650a838 lj_BC_FUNCC + 44 6 libluajit-5.1.2.dylib 0x106517490 lua_pcall + 148 7 libluajit-5.1.2.dylib 0x10650a838 lj_BC_FUNCC + 44 8 libmpv.1.dylib 0x106107444 load_scripts + 376 9 libluajit-5.1.2.dylib 0x10650a838 lj_BC_FUNCC + 44 10 libluajit-5.1.2.dylib 0x106517490 lua_pcall + 148 11 libluajit-5.1.2.dylib 0x10650a838 lj_BC_FUNCC + 44 12 libluajit-5.1.2.dylib 0x1065174d0 lua_cpcall + 28 13 libmpv.1.dylib 0x1061116a4 run_script + 100 14 libmpv.1.dylib 0x106111728 script_thread + 32 15 libsystem_pthread.dylib 0x184c8bfa8 _pthread_start + 148 16 libsystem_pthread.dylib 0x184c86da0 thread_start + 8 Thread 15:: */lua script (console) 0 libsystem_kernel.dylib 0x184c4f710 __psynch_cvwait + 8 1 libsystem_pthread.dylib 0x184c8c574 _pthread_cond_wait + 1232 2 libmpv.1.dylib 0x1060eb7b4 wait_wakeup + 88 3 libmpv.1.dylib 0x1060ec11c mpv_wait_event + 420 4 libmpv.1.dylib 0x106107970 script_raw_wait_event + 120 5 libluajit-5.1.2.dylib 0x10650a838 lj_BC_FUNCC + 44 6 libluajit-5.1.2.dylib 0x106517490 lua_pcall + 148 7 libluajit-5.1.2.dylib 0x10650a838 lj_BC_FUNCC + 44 8 libmpv.1.dylib 0x106107444 load_scripts + 376 9 libluajit-5.1.2.dylib 0x10650a838 lj_BC_FUNCC + 44 10 libluajit-5.1.2.dylib 0x106517490 lua_pcall + 148 11 libluajit-5.1.2.dylib 0x10650a838 lj_BC_FUNCC + 44 12 libluajit-5.1.2.dylib 0x1065174d0 lua_cpcall + 28 13 libmpv.1.dylib 0x1061116a4 run_script + 100 14 libmpv.1.dylib 0x106111728 script_thread + 32 15 libsystem_pthread.dylib 0x184c8bfa8 _pthread_start + 148 16 libsystem_pthread.dylib 0x184c86da0 thread_start + 8 Thread 16:: */ipc socket listener 0 libsystem_kernel.dylib 0x184c54834 poll + 8 1 libmpv.1.dylib 0x1060d2f48 ipc_thread + 368 2 libsystem_pthread.dylib 0x184c8bfa8 _pthread_start + 148 3 libsystem_pthread.dylib 0x184c86da0 thread_start + 8 Thread 17:: caulk.messenger.shared:17 0 libsystem_kernel.dylib 0x184c4be90 semaphore_wait_trap + 8 1 caulk 0x18e2aa024 caulk::semaphore::timed_wait(double) + 212 2 caulk 0x18e2a9ed8 caulk::concurrent::details::worker_thread::run() + 36 3 caulk 0x18e2a9bc8 void* caulk::thread_proxySteps to reproduce: I am not able to reproduce this crash upon demand. This crash occurred during automated testing using the script below attempting to detect race conditions during shutdown.
startQuitLoop.sh:
```bash #!/bin/bash while true; do echo Starting IINA open -a /Users/low-batt/Library/Developer/Xcode/DerivedData/iina-gwhhvjgxybcchtdcwvmukizbfeip/Build/Products/Debug/IINA.app ~/Movies/resume-failure.mp4 sleep 2 echo Instructing IINA to Quit osascript -e 'activate application "IINA"' \ -e 'tell application "System Events" to keystroke "q" using command down' sleep 2 done ```How often does this happen? Very rarely.