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

Fix crash & other LanguageTokenField issues #4074

Merged
merged 1 commit into from Mar 12, 2023

Conversation

svobs
Copy link
Contributor

@svobs svobs commented Nov 12, 2022


Description:

This was a really tricky one.

The crash log wasn't helpful at all, and the problem wasn't at all related to constraints, but it was accurate in hinting about an infinite loop which AppKit was detecting and killing. By placing log statements all over the code and running it, I was able to determine that the infinite loop was coming from the LanguageTokenField class.

For some reason, the tokenField(displayStringForRepresentedObject) and tokenField(representedObjectForEditing) methods were getting called endlessly and at a ratio of about 5:1. I know that AppKit is kind of messy and tends to call methods a lot more than it needs to, so I wasn't really concerned by all the displayStringForRepresentedObject calls, but the smoking gun was the repeated representedObjectForEditing calls, which is where AppKit asks the code what the represented object ("token") should be for the text in the text field. The fact that it was calling it over and over suggested that it either wasn't happy with the result it was getting, or thought it hadn't called it. From my experience doing object-mapping in the past, and seeing that a new Token() was being returned each time, I had a hunch that AppKit wasn't able to establish an identity for the Token objects it was getting back - and that turned out to be correct. I was able to get it to stop crashing by adding an override of isEqual() to the Token class which used its code field to check whether one token was identical to another. (Since isEqual was not overridden before, the system would default to comparing object references, but since a new Token was being returned each time, that would be seen as a new object.)

I don't know why it's doing what it's doing; it's AppKit and the source code isn't available, but during my research I found a commenter who seemed to sum it up well: NSTokenField doesn't really like to be customized. As far as I know, there's nothing documented about the need for a returned token to guarantee identity, and that is a glaring omission on Apple's part.

During the course of this investigation I tore the LanguageTokenField apart and pieced it back together again. There were a number of things which didn't seem like good ideas, like overriding stringValue and the strange use of LayoutManager looking for a Unicode attachment char as a way of figuring out whether the user finished typing. I refactored to get rid of the former...but the latter turned out to be essential, because it was catching cases where the standard events were not getting fired.

But there were a few other issues which I discovered and did fix in this update:

  1. There were some cases where adding or removing tokens were not getting written to the prefs, because controlTextDidChange wasn't getting called. Fixed by adding more listeners.
  2. There was a bug which occurred if a user set some languages and stored them to the prefs, then closed & reopened IINA and went back to the language token field: the Token object was getting its content field set to the same value as its code field. So double-clicking a token to edit it didn't show the full name of the language as it did before. I managed to remove the Token class entirely and replace it with language list lookups. Less code, so less chance for bugs, and still about as fast. Also removes the need to do a custom isEqual, because now it's just comparing Strings.
  3. It looks like language codes were being compared by their lowercase values in some places, but not others. I'm assuming that we don't want fra and Fra to be considered two different languages. So all the entries, including user entries which aren't recognized in the language dict, are now converted to lowercase before being stored in the prefs and before being checked for equality.
  4. I assumed that we don't want the same language code listed twice in the list, so I added some checks to exclude already-added languages from the suggestions list, and added code to drop a duplicate tokens when they are added.

Let me know if that last point was an incorrect assumption to make and I can remove that check.

@uiryuu uiryuu requested a review from lhc70000 November 12, 2022 23:50
@low-batt low-batt linked an issue Nov 13, 2022 that may be closed by this pull request
@low-batt
Copy link
Contributor

Pulled PR and tested. I was not able to reproduce the crash. Great work tracking that down! I did find the following problem that is not fixed. We could treat this as a separate issue.

Type "Fr" and pick the entry for "fro" as shown here:
issue-3505-selecting

After pressing return the result contains "french" as well as the ISO code:
issue-3505-result

It is stored in preferences that way:

low-batt@gag ~$ defaults read com.colliderli.iina subLang
french,fro

Another thing I would change is to sort the list shown to the user. In the first screenshot I would have expected all the French language entries to be together before the entry for Friulian.

@svobs
Copy link
Contributor Author

svobs commented Dec 4, 2022

I had to rewrite the whole thing again. The double entry you pointed out was difficult to work around but I think I've got a workable solution.

Some context:

  • NSTokenField requires each token to have both an editingString (the actual editable value) and a displayString (the label for the token). Each must map 1-to-1 with the other.
  • IINA uses the editingString "as-is" for a token, although in nearly all cases the user has been fed a list of auto-complete suggestions and has chosen one of them, so it will often be set to the description of a language.
  • For the displayString IINA tries to match the editingString with a language's description. If a matching language is found, it uses the match's three-letter code as the displayString. If it doesn't find a match, it just uses the editingString value for displayString also.
  • The same way that there is a duality between each token's editingString and displayString, NSTokenField also has a duality between its objectValue and stringValue, where objectValue is usually a list of tokens, and stringValue is a single String.
  • Thus, there must be a clear-cut way to break up the stringValue into a set of tokens. The default strategy is to use commas as separator chars.

The problem occurred for language descriptions which included commas in them. When a user enters text and then hits ENTER, NSTokenField does not blindly accept it and turn it into a single token. Instead it tries to parse that text and break it into tokens. And it seems to do this somewhere in its implementation which is inaccessible to us.

To work around this, I was able to tell it to use newline delimiters instead of comma delimiters. This fixed the double token creation problem, but it broke copy & paste. The newlines would get stripped out during copy; and paste would only work if they knew to first copy with one lang code per line. Worst of all, it broke the prefs, which have been storing the list as CSV.

So I was able to fix the new problems by adding extra code in the right places to translate from newline-separated-values to comma-separated-values, and back again. The values it saves to the prefs should almost always be language codes, not language descriptions, so using CSV there shouldn't be an issue. But just in case, I made it first replace any comma it found in each token with a semicolon before saving in the prefs.

@svobs
Copy link
Contributor Author

svobs commented Dec 4, 2022

Forgot to mention that I also implemented sorting. It will re-sort as soon as a new token is created, and there is no animation to show the tokens moving around, so hopefully users will be able to figure out what's happening. I considered trying to sort the prefs without also sorting the displayed values, but it looked that that would have introduced a lot of tricky edge cases which I wasn't willing to deal with.

@svobs svobs force-pushed the pr-language-token-crash branch 3 times, most recently from 89afad4 to b99ddbd Compare December 4, 2022 10:50
@svobs
Copy link
Contributor Author

svobs commented Dec 4, 2022

OK, it looks like the infinite loop is back.

EDIT: OK. Fixed again. Yeesh.

@svobs svobs force-pushed the pr-language-token-crash branch 2 times, most recently from 5e57744 to fe345f0 Compare December 5, 2022 01:32
@low-batt
Copy link
Contributor

low-batt commented Dec 5, 2022

I am no longer able to reproduce the problem with storing French in the preference value. Yeah! Good progress!

On this:

Another thing I would change is to sort the display shown to the user. In the above screenshot I would have expected all the French language entries to be together before the entry for Friulian.

The new code does not sort the entries displayed to the user? Instead it is sorting the codes in the stored preference value? I believe that is wrong as the order of codes in the preference represents the user's specified priority order in which IINA should look for subtitle languages. I should be able to set the preference to eng cs to indicate prefer English subtitles, but fall back to Czech if English subtitles can not be found.

The sort order I was concerned about can be shown by this screenshot:
issue-3505-not-sort

The user must hunt around or type more characters to find all the different french codes. Also of note in that screenshot is that the list is not quite wide enough and the code for French, Middle is not visible.

Displaying the list to choose from in sorted order is not critical. The user can type more characters to narrow down the list. Just a nice to have.

So far I've not been able to reproduce this again. I think I had the preferences window open with the list being displayed and then selected Quit from the IINA menu.

Crash Report:
-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Process:               IINA [20006]
Path:                  /Applications/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:             2022-12-04 22:58:01.5113 -0500
OS Version:            macOS 13.0.1 (22A400)
Report Version:        12
Anonymous UUID:        C8F97525-3322-572C-B9CE-A91EB243AC3C

Sleep/Wake UUID:       4B7B18C4-6F79-4766-A6C2-1D68715C3BE9

Time Awake Since Boot: 120000 seconds
Time Since Wake:       5767 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BREAKPOINT (SIGTRAP)
Exception Codes:       0x0000000000000001, 0x0000000188fe70e0

Termination Reason:    Namespace SIGNAL, Code 5 Trace/BPT trap: 5
Terminating Process:   exc handler [20006]

Application Specific Backtrace 0:
0   CoreFoundation                      0x0000000185b28418 __exceptionPreprocess + 176
1   libobjc.A.dylib                     0x0000000185672ea8 objc_exception_throw + 60
2   CoreFoundation                      0x0000000185b282bc +[NSException exceptionWithName:reason:userInfo:] + 0
3   AppKit                              0x0000000188d35cd0 -[NSWindow(NSDisplayCycle) _postWindowNeedsUpdateConstraintsUnlessPostingDisabled] + 1844
4   AppKit                              0x0000000188d1fda8 -[NSView _informContainerThatSubviewsNeedUpdateConstraints] + 64
5   AppKit                              0x0000000188d1fda8 -[NSView _informContainerThatSubviewsNeedUpdateConstraints] + 64
6   AppKit                              0x0000000188d1fda8 -[NSView _informContainerThatSubviewsNeedUpdateConstraints] + 64
7   AppKit                              0x0000000188d1fda8 -[NSView _informContainerThatSubviewsNeedUpdateConstraints] + 64
8   AppKit                              0x0000000188d1fda8 -[NSView _informContainerThatSubviewsNeedUpdateConstraints] + 64
9   AppKit                              0x0000000188d1fda8 -[NSView _informContainerThatSubviewsNeedUpdateConstraints] + 64
10  AppKit                              0x0000000188d1fda8 -[NSView _informContainerThatSubviewsNeedUpdateConstraints] + 64
11  AppKit                              0x0000000188d1fda8 -[NSView _informContainerThatSubviewsNeedUpdateConstraints] + 64
12  AppKit                              0x0000000188d1fd2c -[NSView setNeedsUpdateConstraints:] + 460
13  AppKit                              0x000000018970ef08 -[NSView(NSConstraintBasedLayoutInternal) _invalidateIntrinsicContentSizeDirtyingConstraints:] + 100
14  AppKit                              0x0000000188d38890 -[NSTextField invalidateIntrinsicContentSize] + 52
15  AppKit                              0x0000000188d37f54 -[NSCell setObjectValue:] + 304
16  AppKit                              0x0000000188dcc538 -[NSTokenFieldCell setObjectValue:] + 324
17  AppKit                              0x0000000188d3b8f0 -[NSCell setAttributedStringValue:] + 216
18  AppKit                              0x0000000188fe13f0 -[NSTokenFieldCell _validateEditing:] + 76
19  AppKit                              0x0000000188d39a9c -[NSCell attributedStringValue] + 68
20  AppKit                              0x0000000188d8b4e0 -[NSTextField _performMultiPassIntrinsicSize] + 316
21  AppKit                              0x0000000188d8b184 -[NSTextField updateConstraints] + 40
22  AppKit                              0x00000001894d18b4 ___NSViewUpdateConstraints_block_invoke + 88
23  AppKit                              0x0000000188d476cc NSPerformVisuallyAtomicChange + 108
24  AppKit                              0x0000000188d8a738 _NSViewUpdateConstraints + 96
25  AppKit                              0x0000000188d8a468 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 692
26  AppKit                              0x0000000188d8a324 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 368
27  AppKit                              0x0000000188d8a324 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 368
28  AppKit                              0x0000000188d8a324 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 368
29  AppKit                              0x0000000188d8a324 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 368
30  AppKit                              0x0000000188d8a324 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 368
31  AppKit                              0x0000000188d8a324 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 368
32  AppKit                              0x0000000188d8a324 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 368
33  AppKit                              0x0000000188d960a8 __82-[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:]_block_invoke + 228
34  CoreAutoLayout                      0x000000018d77b514 -[NSISEngine withBehaviors:performModifications:] + 88
35  AppKit                              0x0000000188d8a27c -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 200
36  AppKit                              0x00000001894c7964 __45-[NSView updateConstraintsForSubtreeIfNeeded]_block_invoke_2 + 52
37  CoreAutoLayout                      0x000000018d77b514 -[NSISEngine withBehaviors:performModifications:] + 88
38  AppKit                              0x000000018970bcd4 -[NSView(NSConstraintBasedLayoutInternal) _withAutomaticEngineOptimizationDisabled:] + 48
39  AppKit                              0x0000000188d8a034 __45-[NSView updateConstraintsForSubtreeIfNeeded]_block_invoke + 224
40  AppKit                              0x0000000188d476cc NSPerformVisuallyAtomicChange + 108
41  AppKit                              0x0000000188d89f48 -[NSView updateConstraintsForSubtreeIfNeeded] + 96
42  CoreAutoLayout                      0x000000018d77b514 -[NSISEngine withBehaviors:performModifications:] + 88
43  AppKit                              0x000000018970bcd4 -[NSView(NSConstraintBasedLayoutInternal) _withAutomaticEngineOptimizationDisabled:] + 48
44  AppKit                              0x0000000189715088 -[NSWindow(NSConstraintBasedLayoutInternal) updateConstraintsIfNeeded] + 172
45  AppKit                              0x0000000188daae54 __NSWindowGetDisplayCycleObserverForUpdateConstraints_block_invoke + 364
46  AppKit                              0x0000000188daacb4 NSDisplayCycleObserverInvoke + 168
47  AppKit                              0x0000000188daa910 NSDisplayCycleFlush + 644
48  QuartzCore                          0x000000018d0f2120 _ZN2CA11Transaction19run_commit_handlersE18CATransactionPhase + 120
49  QuartzCore                          0x000000018d0f0ea0 _ZN2CA11Transaction6commitEv + 324
50  AppKit                              0x0000000188e2cb90 __62+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink]_block_invoke + 272
51  AppKit                              0x0000000189509744 ___NSRunLoopObserverCreateWithHandler_block_invoke + 64
52  CoreFoundation                      0x0000000185aacde4 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36
53  CoreFoundation                      0x0000000185aaccd0 __CFRunLoopDoObservers + 532
54  CoreFoundation                      0x0000000185aac308 __CFRunLoopRun + 784
55  CoreFoundation                      0x0000000185aab8a4 CFRunLoopRunSpecific + 612
56  HIToolbox                           0x000000018f11f3bc RunCurrentEventLoopInMode + 292
57  HIToolbox                           0x000000018f11f04c ReceiveNextEventCommon + 236
58  HIToolbox                           0x000000018f11ef48 _BlockUntilNextEventMatchingListInModeWithFilter + 72
59  AppKit                              0x0000000188d04630 _DPSNextEvent + 632
60  AppKit                              0x0000000188d037c0 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 728
61  AppKit                              0x0000000188f263b0 -[NSApplication _shouldTerminate] + 700
62  AppKit                              0x0000000188f18fb0 -[NSApplication terminate:] + 612
63  AppKit                              0x0000000188ead2f0 -[NSApplication(NSResponder) sendAction:to:from:] + 440
64  AppKit                              0x0000000188f79998 -[NSMenuItem _corePerformAction] + 336
65  AppKit                              0x0000000188f79714 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 104
66  AppKit                              0x0000000188fb5710 -[NSMenu performActionForItemAtIndex:] + 200
67  AppKit                              0x0000000188fb5630 -[NSMenu _internalPerformActionForItemAtIndex:] + 76
68  AppKit                              0x0000000188fb5484 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 108
69  AppKit                              0x0000000188f61cdc NSSLMMenuEventHandler + 640
70  HIToolbox                           0x000000018f0f7944 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1092
71  HIToolbox                           0x000000018f0f6dc4 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 356
72  HIToolbox                           0x000000018f10cfd4 SendEventToEventTarget + 40
73  HIToolbox                           0x000000018f16c6bc _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 416
74  HIToolbox                           0x000000018f190ee4 SendMenuCommandWithContextAndModifiers + 56
75  HIToolbox                           0x000000018f190e74 SendMenuItemSelectedEvent + 352
76  HIToolbox                           0x000000018f190ca0 _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 100
77  HIToolbox                           0x000000018f191660 _ZL14MenuSelectCoreP8MenuData5PointdjPP13OpaqueMenuRefPt + 560
78  HIToolbox                           0x000000018f191380 _HandleMenuSelection2 + 416
79  AppKit                              0x0000000188e570f4 _NSHandleCarbonMenuEvent + 256
80  AppKit                              0x0000000188e56f18 _DPSEventHandledByCarbon + 60
81  AppKit                              0x0000000188d03db8 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2256
82  AppKit                              0x0000000188cf7bf0 -[NSApplication run] + 464
83  AppKit                              0x0000000188ccf058 NSApplicationMain + 880
84  IINA                                0x0000000100942428 main + 12
85  dyld                                0x00000001856a3e50 start + 2544


Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   AppKit                        	       0x188fe70e0 -[NSApplication _crashOnException:] + 240
1   AppKit                        	       0x188fe70d8 -[NSApplication _crashOnException:] + 232
2   AppKit                        	       0x188e2cd04 __62+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink]_block_invoke + 644
3   AppKit                        	       0x189509744 ___NSRunLoopObserverCreateWithHandler_block_invoke + 64
4   CoreFoundation                	       0x185aacde4 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36
5   CoreFoundation                	       0x185aaccd0 __CFRunLoopDoObservers + 532
6   CoreFoundation                	       0x185aac308 __CFRunLoopRun + 784
7   CoreFoundation                	       0x185aab8a4 CFRunLoopRunSpecific + 612
8   HIToolbox                     	       0x18f11f3bc RunCurrentEventLoopInMode + 292
9   HIToolbox                     	       0x18f11f04c ReceiveNextEventCommon + 236
10  HIToolbox                     	       0x18f11ef48 _BlockUntilNextEventMatchingListInModeWithFilter + 72
11  AppKit                        	       0x188d04630 _DPSNextEvent + 632
12  AppKit                        	       0x188d037c0 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 728
13  AppKit                        	       0x188f263b0 -[NSApplication _shouldTerminate] + 700
14  AppKit                        	       0x188f18fb0 -[NSApplication terminate:] + 612
15  AppKit                        	       0x188ead2f0 -[NSApplication(NSResponder) sendAction:to:from:] + 440
16  AppKit                        	       0x188f79998 -[NSMenuItem _corePerformAction] + 336
17  AppKit                        	       0x188f79714 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 104
18  AppKit                        	       0x188fb5710 -[NSMenu performActionForItemAtIndex:] + 200
19  AppKit                        	       0x188fb5630 -[NSMenu _internalPerformActionForItemAtIndex:] + 76
20  AppKit                        	       0x188fb5484 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 108
21  AppKit                        	       0x188f61cdc NSSLMMenuEventHandler + 640
22  HIToolbox                     	       0x18f0f7944 DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) + 1092
23  HIToolbox                     	       0x18f0f6dc4 SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*) + 356
24  HIToolbox                     	       0x18f10cfd4 SendEventToEventTarget + 40
25  HIToolbox                     	       0x18f16c6bc SendHICommandEvent(unsigned int, HICommand const*, unsigned int, unsigned int, unsigned char, void const*, OpaqueEventTargetRef*, OpaqueEventTargetRef*, OpaqueEventRef**) + 416
26  HIToolbox                     	       0x18f190ee4 SendMenuCommandWithContextAndModifiers + 56
27  HIToolbox                     	       0x18f190e74 SendMenuItemSelectedEvent + 352
28  HIToolbox                     	       0x18f190ca0 FinishMenuSelection(SelectionData*, MenuResult*, MenuResult*) + 100
29  HIToolbox                     	       0x18f191660 MenuSelectCore(MenuData*, Point, double, unsigned int, OpaqueMenuRef**, unsigned short*) + 560
30  HIToolbox                     	       0x18f191380 _HandleMenuSelection2 + 416
31  AppKit                        	       0x188e570f4 _NSHandleCarbonMenuEvent + 256
32  AppKit                        	       0x188e56f18 _DPSEventHandledByCarbon + 60
33  AppKit                        	       0x188d03db8 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2256
34  AppKit                        	       0x188cf7bf0 -[NSApplication run] + 464
35  AppKit                        	       0x188ccf058 NSApplicationMain + 880
36  IINA                          	       0x100942428 main + 12
37  dyld                          	       0x1856a3e50 start + 2544

Thread 1:: caulk.messenger.shared:17
0   libsystem_kernel.dylib        	       0x18598ed6c semaphore_wait_trap + 8
1   caulk                         	       0x18ee46cfc caulk::mach::semaphore::wait_or_error() + 28
2   caulk                         	       0x18ee29634 caulk::concurrent::details::worker_thread::run() + 56
3   caulk                         	       0x18ee29278 void* caulk::thread_proxy<std::__1::tuple<caulk::thread::attributes, void (caulk::concurrent::details::worker_thread::*)(), std::__1::tuple<caulk::concurrent::details::worker_thread*> > >(void*) + 96
4   libsystem_pthread.dylib       	       0x1859ce06c _pthread_start + 148
5   libsystem_pthread.dylib       	       0x1859c8e2c thread_start + 8

Thread 2:: com.apple.NSEventThread
0   libsystem_kernel.dylib        	       0x18598edf0 mach_msg2_trap + 8
1   libsystem_kernel.dylib        	       0x1859a08d8 mach_msg2_internal + 80
2   libsystem_kernel.dylib        	       0x185997638 mach_msg_overwrite + 540
3   libsystem_kernel.dylib        	       0x18598f16c mach_msg + 24
4   CoreFoundation                	       0x185aadbdc __CFRunLoopServiceMachPort + 160
5   CoreFoundation                	       0x185aac4c8 __CFRunLoopRun + 1232
6   CoreFoundation                	       0x185aab8a4 CFRunLoopRunSpecific + 612
7   AppKit                        	       0x188e2e248 _NSEventThread + 172
8   libsystem_pthread.dylib       	       0x1859ce06c _pthread_start + 148
9   libsystem_pthread.dylib       	       0x1859c8e2c thread_start + 8

Thread 3:
0   libsystem_pthread.dylib       	       0x1859c8e18 start_wqthread + 0


Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000156200e00   x1: 0x000000015613b675   x2: 0xfffffffffffffff4   x3: 0x0000000156203454
    x4: 0xfffffffffff38201   x5: 0x0000000000000020   x6: 0x0000000156200e00   x7: 0x0000000000002694
    x8: 0x00000001dec67000   x9: 0xe57d3c2f69a900bd  x10: 0xe57d3c2f69a900bd  x11: 0x000000000000007f
   x12: 0x0000000000000018  x13: 0x00000001559d1d70  x14: 0x01000001e10ac5b1  x15: 0x00000001e10ac5b0
   x16: 0x00000001859fbed0  x17: 0x00000001e20122b8  x18: 0x0000000000000000  x19: 0x0000600002eaf1b0
   x20: 0x00006000036c4040  x21: 0x000002a35cd10bab  x22: 0x00000001559e3548  x23: 0x000000016f4c12b0
   x24: 0x00000001559e3540  x25: 0x0000000000000002  x26: 0x00006000012c1e00  x27: 0x0000600002d22370
   x28: 0x0000000185aad354   fp: 0x000000016f4c1120   lr: 0x2c11800188fe70d8
    sp: 0x000000016f4c10f0   pc: 0x0000000188fe70e0 cpsr: 0x60001000
   far: 0x0000600002cdc000  esr: 0xf2000001 (Breakpoint) brk 1

Binary Images:
       0x188ccb000 -        0x189bd2fff com.apple.AppKit (6.9) <af9f6891-70ad-3c26-af08-b747344892d2> /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit
       0x185a2c000 -        0x185f03fff com.apple.CoreFoundation (6.9) <f4ff83fc-e62c-30b4-b3a9-876c8a1fd595> /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
       0x18f0ed000 -        0x18f420fff com.apple.HIToolbox (2.1.1) <02b9797f-c47d-30b7-b7b0-802d0d26f31c> /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/HIToolbox
       0x10093c000 -        0x100bebfff com.colliderli.iina (1.3.1) <da58f4cc-7901-3bca-a111-34e5236b0261> /Applications/IINA.app/Contents/MacOS/IINA
       0x18569e000 -        0x1857284bf dyld (*) <de46dd52-4994-3fd8-b4b4-e352a1a19354> /usr/lib/dyld
       0x18598e000 -        0x1859c6ffb libsystem_kernel.dylib (*) <6d6644d3-3db3-34c4-b1e3-c675ec5360f0> /usr/lib/system/libsystem_kernel.dylib
       0x18ee27000 -        0x18ee50fff com.apple.audio.caulk (1.0) <445d1341-52c5-3468-ba85-f01410317744> /System/Library/PrivateFrameworks/caulk.framework/Versions/A/caulk
       0x1859c7000 -        0x1859d3ffb libsystem_pthread.dylib (*) <886caca0-5762-3640-8db2-3fa3b911c062> /usr/lib/system/libsystem_pthread.dylib

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 53
    thread_create: 0
    thread_set_state: 2744

VM Region Summary:
ReadOnly portion of Libraries: Total=1.3G resident=0K(0%) swapped_out_or_unallocated=1.3G(100%)
Writable regions: Total=1.7G written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=1.7G(100%)

                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
Accelerate framework              1408K       11 
Activity Tracing                   256K        1 
CG backing stores                 4032K        4 
CG image                          1680K       36 
ColorSync                          624K       28 
CoreAnimation                     10.2M      244 
CoreGraphics                        32K        2 
CoreUI image data                 5632K       42 
Foundation                          48K        2 
Kernel Alloc Once                   32K        1 
MALLOC                           311.3M       59 
MALLOC guard page                  192K       10 
MALLOC_MEDIUM (reserved)         960.0M        8         reserved VM address space (unallocated)
MALLOC_NANO (reserved)           384.0M        1         reserved VM address space (unallocated)
STACK GUARD                       56.1M        4 
Stack                             9808K        4 
VM_ALLOCATE                       1568K       25 
__AUTH                            1791K      344 
__AUTH_CONST                      24.0M      561 
__CTF                               756        1 
__DATA                            21.6M      622 
__DATA_CONST                      29.3M      631 
__DATA_DIRTY                      1974K      221 
__FONT_DATA                        2352        1 
__LINKEDIT                       773.1M       69 
__OBJC_CONST                      4536K      309 
__OBJC_RO                         65.1M        1 
__OBJC_RW                         1981K        1 
__TEXT                           608.7M      654 
dyld private memory                256K        1 
mapped file                      242.7M       53 
shared memory                      928K       18 
===========                     =======  ======= 
TOTAL                              3.4G     3969 
TOTAL, minus reserved VM space     2.1G     3969 



-----------
Full Report
-----------

{"app_name":"IINA","timestamp":"2022-12-04 22:58:06.00 -0500","app_version":"1.3.1","slice_uuid":"da58f4cc-7901-3bca-a111-34e5236b0261","build_version":"133","platform":1,"bundleID":"com.colliderli.iina","share_with_app_devs":0,"is_first_party":0,"bug_type":"309","os_version":"macOS 13.0.1 (22A400)","roots_installed":0,"name":"IINA","incident_id":"17AF5FB7-BB47-4EB8-B90B-09EF3BF97EC6"}
{
  "uptime" : 120000,
  "procRole" : "Foreground",
  "version" : 2,
  "userID" : 503,
  "deployVersion" : 210,
  "modelCode" : "MacBookPro18,2",
  "coalitionID" : 7863,
  "osVersion" : {
    "train" : "macOS 13.0.1",
    "build" : "22A400",
    "releaseType" : "User"
  },
  "captureTime" : "2022-12-04 22:58:01.5113 -0500",
  "incident" : "17AF5FB7-BB47-4EB8-B90B-09EF3BF97EC6",
  "pid" : 20006,
  "translated" : false,
  "cpuType" : "ARM-64",
  "roots_installed" : 0,
  "bug_type" : "309",
  "procLaunch" : "2022-12-04 22:56:47.5853 -0500",
  "procStartAbsTime" : 2899116335927,
  "procExitAbsTime" : 2900890242684,
  "procName" : "IINA",
  "procPath" : "\/Applications\/IINA.app\/Contents\/MacOS\/IINA",
  "bundleInfo" : {"CFBundleShortVersionString":"1.3.1","CFBundleVersion":"133","CFBundleIdentifier":"com.colliderli.iina"},
  "storeInfo" : {"deviceIdentifierForVendor":"0DD90AC0-3D63-58F1-A6EE-E2F0CA390821","thirdParty":true},
  "parentProc" : "launchd",
  "parentPid" : 1,
  "coalitionName" : "com.colliderli.iina",
  "crashReporterKey" : "C8F97525-3322-572C-B9CE-A91EB243AC3C",
  "wakeTime" : 5767,
  "sleepWakeUUID" : "4B7B18C4-6F79-4766-A6C2-1D68715C3BE9",
  "sip" : "enabled",
  "exception" : {"codes":"0x0000000000000001, 0x0000000188fe70e0","rawCodes":[1,6593343712],"type":"EXC_BREAKPOINT","signal":"SIGTRAP"},
  "termination" : {"flags":0,"code":5,"namespace":"SIGNAL","indicator":"Trace\/BPT trap: 5","byProc":"exc handler","byPid":20006},
  "os_fault" : {"process":"IINA"},
  "asiBacktraces" : ["0   CoreFoundation                      0x0000000185b28418 __exceptionPreprocess + 176\n1   libobjc.A.dylib                     0x0000000185672ea8 objc_exception_throw + 60\n2   CoreFoundation                      0x0000000185b282bc +[NSException exceptionWithName:reason:userInfo:] + 0\n3   AppKit                              0x0000000188d35cd0 -[NSWindow(NSDisplayCycle) _postWindowNeedsUpdateConstraintsUnlessPostingDisabled] + 1844\n4   AppKit                              0x0000000188d1fda8 -[NSView _informContainerThatSubviewsNeedUpdateConstraints] + 64\n5   AppKit                              0x0000000188d1fda8 -[NSView _informContainerThatSubviewsNeedUpdateConstraints] + 64\n6   AppKit                              0x0000000188d1fda8 -[NSView _informContainerThatSubviewsNeedUpdateConstraints] + 64\n7   AppKit                              0x0000000188d1fda8 -[NSView _informContainerThatSubviewsNeedUpdateConstraints] + 64\n8   AppKit                              0x0000000188d1fda8 -[NSView _informContainerThatSubviewsNeedUpdateConstraints] + 64\n9   AppKit                              0x0000000188d1fda8 -[NSView _informContainerThatSubviewsNeedUpdateConstraints] + 64\n10  AppKit                              0x0000000188d1fda8 -[NSView _informContainerThatSubviewsNeedUpdateConstraints] + 64\n11  AppKit                              0x0000000188d1fda8 -[NSView _informContainerThatSubviewsNeedUpdateConstraints] + 64\n12  AppKit                              0x0000000188d1fd2c -[NSView setNeedsUpdateConstraints:] + 460\n13  AppKit                              0x000000018970ef08 -[NSView(NSConstraintBasedLayoutInternal) _invalidateIntrinsicContentSizeDirtyingConstraints:] + 100\n14  AppKit                              0x0000000188d38890 -[NSTextField invalidateIntrinsicContentSize] + 52\n15  AppKit                              0x0000000188d37f54 -[NSCell setObjectValue:] + 304\n16  AppKit                              0x0000000188dcc538 -[NSTokenFieldCell setObjectValue:] + 324\n17  AppKit                              0x0000000188d3b8f0 -[NSCell setAttributedStringValue:] + 216\n18  AppKit                              0x0000000188fe13f0 -[NSTokenFieldCell _validateEditing:] + 76\n19  AppKit                              0x0000000188d39a9c -[NSCell attributedStringValue] + 68\n20  AppKit                              0x0000000188d8b4e0 -[NSTextField _performMultiPassIntrinsicSize] + 316\n21  AppKit                              0x0000000188d8b184 -[NSTextField updateConstraints] + 40\n22  AppKit                              0x00000001894d18b4 ___NSViewUpdateConstraints_block_invoke + 88\n23  AppKit                              0x0000000188d476cc NSPerformVisuallyAtomicChange + 108\n24  AppKit                              0x0000000188d8a738 _NSViewUpdateConstraints + 96\n25  AppKit                              0x0000000188d8a468 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 692\n26  AppKit                              0x0000000188d8a324 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 368\n27  AppKit                              0x0000000188d8a324 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 368\n28  AppKit                              0x0000000188d8a324 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 368\n29  AppKit                              0x0000000188d8a324 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 368\n30  AppKit                              0x0000000188d8a324 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 368\n31  AppKit                              0x0000000188d8a324 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 368\n32  AppKit                              0x0000000188d8a324 -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 368\n33  AppKit                              0x0000000188d960a8 __82-[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:]_block_invoke + 228\n34  CoreAutoLayout                      0x000000018d77b514 -[NSISEngine withBehaviors:performModifications:] + 88\n35  AppKit                              0x0000000188d8a27c -[NSView _updateConstraintsForSubtreeIfNeededCollectingViewsWithInvalidBaselines:] + 200\n36  AppKit                              0x00000001894c7964 __45-[NSView updateConstraintsForSubtreeIfNeeded]_block_invoke_2 + 52\n37  CoreAutoLayout                      0x000000018d77b514 -[NSISEngine withBehaviors:performModifications:] + 88\n38  AppKit                              0x000000018970bcd4 -[NSView(NSConstraintBasedLayoutInternal) _withAutomaticEngineOptimizationDisabled:] + 48\n39  AppKit                              0x0000000188d8a034 __45-[NSView updateConstraintsForSubtreeIfNeeded]_block_invoke + 224\n40  AppKit                              0x0000000188d476cc NSPerformVisuallyAtomicChange + 108\n41  AppKit                              0x0000000188d89f48 -[NSView updateConstraintsForSubtreeIfNeeded] + 96\n42  CoreAutoLayout                      0x000000018d77b514 -[NSISEngine withBehaviors:performModifications:] + 88\n43  AppKit                              0x000000018970bcd4 -[NSView(NSConstraintBasedLayoutInternal) _withAutomaticEngineOptimizationDisabled:] + 48\n44  AppKit                              0x0000000189715088 -[NSWindow(NSConstraintBasedLayoutInternal) updateConstraintsIfNeeded] + 172\n45  AppKit                              0x0000000188daae54 __NSWindowGetDisplayCycleObserverForUpdateConstraints_block_invoke + 364\n46  AppKit                              0x0000000188daacb4 NSDisplayCycleObserverInvoke + 168\n47  AppKit                              0x0000000188daa910 NSDisplayCycleFlush + 644\n48  QuartzCore                          0x000000018d0f2120 _ZN2CA11Transaction19run_commit_handlersE18CATransactionPhase + 120\n49  QuartzCore                          0x000000018d0f0ea0 _ZN2CA11Transaction6commitEv + 324\n50  AppKit                              0x0000000188e2cb90 __62+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink]_block_invoke + 272\n51  AppKit                              0x0000000189509744 ___NSRunLoopObserverCreateWithHandler_block_invoke + 64\n52  CoreFoundation                      0x0000000185aacde4 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36\n53  CoreFoundation                      0x0000000185aaccd0 __CFRunLoopDoObservers + 532\n54  CoreFoundation                      0x0000000185aac308 __CFRunLoopRun + 784\n55  CoreFoundation                      0x0000000185aab8a4 CFRunLoopRunSpecific + 612\n56  HIToolbox                           0x000000018f11f3bc RunCurrentEventLoopInMode + 292\n57  HIToolbox                           0x000000018f11f04c ReceiveNextEventCommon + 236\n58  HIToolbox                           0x000000018f11ef48 _BlockUntilNextEventMatchingListInModeWithFilter + 72\n59  AppKit                              0x0000000188d04630 _DPSNextEvent + 632\n60  AppKit                              0x0000000188d037c0 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 728\n61  AppKit                              0x0000000188f263b0 -[NSApplication _shouldTerminate] + 700\n62  AppKit                              0x0000000188f18fb0 -[NSApplication terminate:] + 612\n63  AppKit                              0x0000000188ead2f0 -[NSApplication(NSResponder) sendAction:to:from:] + 440\n64  AppKit                              0x0000000188f79998 -[NSMenuItem _corePerformAction] + 336\n65  AppKit                              0x0000000188f79714 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 104\n66  AppKit                              0x0000000188fb5710 -[NSMenu performActionForItemAtIndex:] + 200\n67  AppKit                              0x0000000188fb5630 -[NSMenu _internalPerformActionForItemAtIndex:] + 76\n68  AppKit                              0x0000000188fb5484 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 108\n69  AppKit                              0x0000000188f61cdc NSSLMMenuEventHandler + 640\n70  HIToolbox                           0x000000018f0f7944 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1092\n71  HIToolbox                           0x000000018f0f6dc4 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 356\n72  HIToolbox                           0x000000018f10cfd4 SendEventToEventTarget + 40\n73  HIToolbox                           0x000000018f16c6bc _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 416\n74  HIToolbox                           0x000000018f190ee4 SendMenuCommandWithContextAndModifiers + 56\n75  HIToolbox                           0x000000018f190e74 SendMenuItemSelectedEvent + 352\n76  HIToolbox                           0x000000018f190ca0 _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 100\n77  HIToolbox                           0x000000018f191660 _ZL14MenuSelectCoreP8MenuData5PointdjPP13OpaqueMenuRefPt + 560\n78  HIToolbox                           0x000000018f191380 _HandleMenuSelection2 + 416\n79  AppKit                              0x0000000188e570f4 _NSHandleCarbonMenuEvent + 256\n80  AppKit                              0x0000000188e56f18 _DPSEventHandledByCarbon + 60\n81  AppKit                              0x0000000188d03db8 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2256\n82  AppKit                              0x0000000188cf7bf0 -[NSApplication run] + 464\n83  AppKit                              0x0000000188ccf058 NSApplicationMain + 880\n84  IINA                                0x0000000100942428 main + 12\n85  dyld                                0x00000001856a3e50 start + 2544"],
  "extMods" : {"caller":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"system":{"thread_create":0,"thread_set_state":2744,"task_for_pid":53},"targeted":{"thread_create":0,"thread_set_state":0,"task_for_pid":0},"warnings":0},
  "faultingThread" : 0,
  "threads" : [{"triggered":true,"id":1916262,"threadState":{"x":[{"value":5739908608},{"value":5739099765},{"value":18446744073709551604},{"value":5739918420},{"value":18446744073708732929},{"value":32},{"value":5739908608},{"value":9876},{"value":8032514048,"symbolLocation":72,"symbol":"_OBJC_PROTOCOL_$_NSCollectionLayoutContainer"},{"value":16536439581108142269},{"value":16536439581108142269},{"value":127},{"value":24},{"value":5731327344},{"value":72057602108474801,"symbolLocation":72057594037927937,"symbol":"OBJC_CLASS_$___NSCFString"},{"value":8070546864,"symbolLocation":0,"symbol":"OBJC_CLASS_$___NSCFString"},{"value":6536806096,"symbolLocation":0,"symbol":"_platform_memmove"},{"value":8086692536},{"value":0},{"value":105553165218224},{"value":105553173692480},{"value":2900660128683},{"value":5731398984},{"value":6162223792},{"value":5731398976},{"value":2},{"value":105553135934976},{"value":105553163592560},{"value":6537532244,"symbolLocation":0,"symbol":"_runLoopObserverWithBlockContext"}],"flavor":"ARM_THREAD_STATE64","lr":{"value":3175459956354609368},"cpsr":{"value":1610616832},"fp":{"value":6162223392},"sp":{"value":6162223344},"esr":{"value":4060086273,"description":"(Breakpoint) brk 1"},"pc":{"value":6593343712,"matchesCrashFrame":1},"far":{"value":105553163304960}},"queue":"com.apple.main-thread","frames":[{"imageOffset":3260640,"symbol":"-[NSApplication _crashOnException:]","symbolLocation":240,"imageIndex":0},{"imageOffset":3260632,"symbol":"-[NSApplication _crashOnException:]","symbolLocation":232,"imageIndex":0},{"imageOffset":1449220,"symbol":"__62+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink]_block_invoke","symbolLocation":644,"imageIndex":0},{"imageOffset":8644420,"symbol":"___NSRunLoopObserverCreateWithHandler_block_invoke","symbolLocation":64,"imageIndex":0},{"imageOffset":527844,"symbol":"__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__","symbolLocation":36,"imageIndex":1},{"imageOffset":527568,"symbol":"__CFRunLoopDoObservers","symbolLocation":532,"imageIndex":1},{"imageOffset":525064,"symbol":"__CFRunLoopRun","symbolLocation":784,"imageIndex":1},{"imageOffset":522404,"symbol":"CFRunLoopRunSpecific","symbolLocation":612,"imageIndex":1},{"imageOffset":205756,"symbol":"RunCurrentEventLoopInMode","symbolLocation":292,"imageIndex":2},{"imageOffset":204876,"symbol":"ReceiveNextEventCommon","symbolLocation":236,"imageIndex":2},{"imageOffset":204616,"symbol":"_BlockUntilNextEventMatchingListInModeWithFilter","symbolLocation":72,"imageIndex":2},{"imageOffset":235056,"symbol":"_DPSNextEvent","symbolLocation":632,"imageIndex":0},{"imageOffset":231360,"symbol":"-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]","symbolLocation":728,"imageIndex":0},{"imageOffset":2470832,"symbol":"-[NSApplication _shouldTerminate]","symbolLocation":700,"imageIndex":0},{"imageOffset":2416560,"symbol":"-[NSApplication terminate:]","symbolLocation":612,"imageIndex":0},{"imageOffset":1975024,"symbol":"-[NSApplication(NSResponder) sendAction:to:from:]","symbolLocation":440,"imageIndex":0},{"imageOffset":2812312,"symbol":"-[NSMenuItem _corePerformAction]","symbolLocation":336,"imageIndex":0},{"imageOffset":2811668,"symbol":"-[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:]","symbolLocation":104,"imageIndex":0},{"imageOffset":3057424,"symbol":"-[NSMenu performActionForItemAtIndex:]","symbolLocation":200,"imageIndex":0},{"imageOffset":3057200,"symbol":"-[NSMenu _internalPerformActionForItemAtIndex:]","symbolLocation":76,"imageIndex":0},{"imageOffset":3056772,"symbol":"-[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:]","symbolLocation":108,"imageIndex":0},{"imageOffset":2714844,"symbol":"NSSLMMenuEventHandler","symbolLocation":640,"imageIndex":0},{"imageOffset":43332,"symbol":"DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*)","symbolLocation":1092,"imageIndex":2},{"imageOffset":40388,"symbol":"SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*)","symbolLocation":356,"imageIndex":2},{"imageOffset":131028,"symbol":"SendEventToEventTarget","symbolLocation":40,"imageIndex":2},{"imageOffset":521916,"symbol":"SendHICommandEvent(unsigned int, HICommand const*, unsigned int, unsigned int, unsigned char, void const*, OpaqueEventTargetRef*, OpaqueEventTargetRef*, OpaqueEventRef**)","symbolLocation":416,"imageIndex":2},{"imageOffset":671460,"symbol":"SendMenuCommandWithContextAndModifiers","symbolLocation":56,"imageIndex":2},{"imageOffset":671348,"symbol":"SendMenuItemSelectedEvent","symbolLocation":352,"imageIndex":2},{"imageOffset":670880,"symbol":"FinishMenuSelection(SelectionData*, MenuResult*, MenuResult*)","symbolLocation":100,"imageIndex":2},{"imageOffset":673376,"symbol":"MenuSelectCore(MenuData*, Point, double, unsigned int, OpaqueMenuRef**, unsigned short*)","symbolLocation":560,"imageIndex":2},{"imageOffset":672640,"symbol":"_HandleMenuSelection2","symbolLocation":416,"imageIndex":2},{"imageOffset":1622260,"symbol":"_NSHandleCarbonMenuEvent","symbolLocation":256,"imageIndex":0},{"imageOffset":1621784,"symbol":"_DPSEventHandledByCarbon","symbolLocation":60,"imageIndex":0},{"imageOffset":232888,"symbol":"-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]","symbolLocation":2256,"imageIndex":0},{"imageOffset":183280,"symbol":"-[NSApplication run]","symbolLocation":464,"imageIndex":0},{"imageOffset":16472,"symbol":"NSApplicationMain","symbolLocation":880,"imageIndex":0},{"imageOffset":25640,"symbol":"main","symbolLocation":12,"imageIndex":3},{"imageOffset":24144,"symbol":"start","symbolLocation":2544,"imageIndex":4}]},{"id":1916332,"name":"caulk.messenger.shared:17","frames":[{"imageOffset":3436,"symbol":"semaphore_wait_trap","symbolLocation":8,"imageIndex":5},{"imageOffset":130300,"symbol":"caulk::mach::semaphore::wait_or_error()","symbolLocation":28,"imageIndex":6},{"imageOffset":9780,"symbol":"caulk::concurrent::details::worker_thread::run()","symbolLocation":56,"imageIndex":6},{"imageOffset":8824,"symbol":"void* caulk::thread_proxy<std::__1::tuple<caulk::thread::attributes, void (caulk::concurrent::details::worker_thread::*)(), std::__1::tuple<caulk::concurrent::details::worker_thread*> > >(void*)","symbolLocation":96,"imageIndex":6},{"imageOffset":28780,"symbol":"_pthread_start","symbolLocation":148,"imageIndex":7},{"imageOffset":7724,"symbol":"thread_start","symbolLocation":8,"imageIndex":7}]},{"id":1916375,"name":"com.apple.NSEventThread","frames":[{"imageOffset":3568,"symbol":"mach_msg2_trap","symbolLocation":8,"imageIndex":5},{"imageOffset":75992,"symbol":"mach_msg2_internal","symbolLocation":80,"imageIndex":5},{"imageOffset":38456,"symbol":"mach_msg_overwrite","symbolLocation":540,"imageIndex":5},{"imageOffset":4460,"symbol":"mach_msg","symbolLocation":24,"imageIndex":5},{"imageOffset":531420,"symbol":"__CFRunLoopServiceMachPort","symbolLocation":160,"imageIndex":1},{"imageOffset":525512,"symbol":"__CFRunLoopRun","symbolLocation":1232,"imageIndex":1},{"imageOffset":522404,"symbol":"CFRunLoopRunSpecific","symbolLocation":612,"imageIndex":1},{"imageOffset":1454664,"symbol":"_NSEventThread","symbolLocation":172,"imageIndex":0},{"imageOffset":28780,"symbol":"_pthread_start","symbolLocation":148,"imageIndex":7},{"imageOffset":7724,"symbol":"thread_start","symbolLocation":8,"imageIndex":7}]},{"id":1917079,"frames":[{"imageOffset":7704,"symbol":"start_wqthread","symbolLocation":0,"imageIndex":7}]}],
  "usedImages" : [
  {
    "source" : "P",
    "arch" : "arm64e",
    "base" : 6590083072,
    "CFBundleShortVersionString" : "6.9",
    "CFBundleIdentifier" : "com.apple.AppKit",
    "size" : 15761408,
    "uuid" : "af9f6891-70ad-3c26-af08-b747344892d2",
    "path" : "\/System\/Library\/Frameworks\/AppKit.framework\/Versions\/C\/AppKit",
    "name" : "AppKit",
    "CFBundleVersion" : "2299"
  },
  {
    "source" : "P",
    "arch" : "arm64e",
    "base" : 6537003008,
    "CFBundleShortVersionString" : "6.9",
    "CFBundleIdentifier" : "com.apple.CoreFoundation",
    "size" : 5079040,
    "uuid" : "f4ff83fc-e62c-30b4-b3a9-876c8a1fd595",
    "path" : "\/System\/Library\/Frameworks\/CoreFoundation.framework\/Versions\/A\/CoreFoundation",
    "name" : "CoreFoundation",
    "CFBundleVersion" : "1953.1"
  },
  {
    "source" : "P",
    "arch" : "arm64e",
    "base" : 6695079936,
    "CFBundleShortVersionString" : "2.1.1",
    "CFBundleIdentifier" : "com.apple.HIToolbox",
    "size" : 3358720,
    "uuid" : "02b9797f-c47d-30b7-b7b0-802d0d26f31c",
    "path" : "\/System\/Library\/Frameworks\/Carbon.framework\/Versions\/A\/Frameworks\/HIToolbox.framework\/Versions\/A\/HIToolbox",
    "name" : "HIToolbox"
  },
  {
    "source" : "P",
    "arch" : "arm64",
    "base" : 4304650240,
    "CFBundleShortVersionString" : "1.3.1",
    "CFBundleIdentifier" : "com.colliderli.iina",
    "size" : 2818048,
    "uuid" : "da58f4cc-7901-3bca-a111-34e5236b0261",
    "path" : "\/Applications\/IINA.app\/Contents\/MacOS\/IINA",
    "name" : "IINA",
    "CFBundleVersion" : "133"
  },
  {
    "source" : "P",
    "arch" : "arm64e",
    "base" : 6533275648,
    "size" : 566464,
    "uuid" : "de46dd52-4994-3fd8-b4b4-e352a1a19354",
    "path" : "\/usr\/lib\/dyld",
    "name" : "dyld"
  },
  {
    "source" : "P",
    "arch" : "arm64e",
    "base" : 6536355840,
    "size" : 233468,
    "uuid" : "6d6644d3-3db3-34c4-b1e3-c675ec5360f0",
    "path" : "\/usr\/lib\/system\/libsystem_kernel.dylib",
    "name" : "libsystem_kernel.dylib"
  },
  {
    "source" : "P",
    "arch" : "arm64e",
    "base" : 6692171776,
    "CFBundleShortVersionString" : "1.0",
    "CFBundleIdentifier" : "com.apple.audio.caulk",
    "size" : 172032,
    "uuid" : "445d1341-52c5-3468-ba85-f01410317744",
    "path" : "\/System\/Library\/PrivateFrameworks\/caulk.framework\/Versions\/A\/caulk",
    "name" : "caulk"
  },
  {
    "source" : "P",
    "arch" : "arm64e",
    "base" : 6536589312,
    "size" : 53244,
    "uuid" : "886caca0-5762-3640-8db2-3fa3b911c062",
    "path" : "\/usr\/lib\/system\/libsystem_pthread.dylib",
    "name" : "libsystem_pthread.dylib"
  }
],
  "sharedCache" : {
  "base" : 6532628480,
  "size" : 3403612160,
  "uuid" : "2d053604-1cb6-3821-a8df-360eb2eb519b"
},
  "vmSummary" : "ReadOnly portion of Libraries: Total=1.3G resident=0K(0%) swapped_out_or_unallocated=1.3G(100%)\nWritable regions: Total=1.7G written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=1.7G(100%)\n\n                                VIRTUAL   REGION \nREGION TYPE                        SIZE    COUNT (non-coalesced) \n===========                     =======  ======= \nAccelerate framework              1408K       11 \nActivity Tracing                   256K        1 \nCG backing stores                 4032K        4 \nCG image                          1680K       36 \nColorSync                          624K       28 \nCoreAnimation                     10.2M      244 \nCoreGraphics                        32K        2 \nCoreUI image data                 5632K       42 \nFoundation                          48K        2 \nKernel Alloc Once                   32K        1 \nMALLOC                           311.3M       59 \nMALLOC guard page                  192K       10 \nMALLOC_MEDIUM (reserved)         960.0M        8         reserved VM address space (unallocated)\nMALLOC_NANO (reserved)           384.0M        1         reserved VM address space (unallocated)\nSTACK GUARD                       56.1M        4 \nStack                             9808K        4 \nVM_ALLOCATE                       1568K       25 \n__AUTH                            1791K      344 \n__AUTH_CONST                      24.0M      561 \n__CTF                               756        1 \n__DATA                            21.6M      622 \n__DATA_CONST                      29.3M      631 \n__DATA_DIRTY                      1974K      221 \n__FONT_DATA                        2352        1 \n__LINKEDIT                       773.1M       69 \n__OBJC_CONST                      4536K      309 \n__OBJC_RO                         65.1M        1 \n__OBJC_RW                         1981K        1 \n__TEXT                           608.7M      654 \ndyld private memory                256K        1 \nmapped file                      242.7M       53 \nshared memory                      928K       18 \n===========                     =======  ======= \nTOTAL                              3.4G     3969 \nTOTAL, minus reserved VM space     2.1G     3969 \n",
  "legacyInfo" : {
  "threadTriggered" : {
    "queue" : "com.apple.main-thread"
  }
},
  "trialInfo" : {
  "rollouts" : [
    {
      "rolloutId" : "60da5e84ab0ca017dace9abf",
      "factorPackIds" : {

      },
      "deploymentId" : 240000008
    },
    {
      "rolloutId" : "6112e3d2fc54bc3389840661",
      "factorPackIds" : {
        "SIRI_TEXT_TO_SPEECH" : "6344d89e13acce15305b79d6"
      },
      "deploymentId" : 240000208
    }
  ],
  "experiments" : [

  ]
}
}

Model: MacBookPro18,2, BootROM 8419.41.10, proc 10:8:2 processors, 64 GB, SMC 
Graphics: Apple M1 Max, Apple M1 Max, Built-In
Display: Color LCD, 3456 x 2234 Retina, Main, MirrorOff, Online
Memory Module: LPDDR5, Hynix
AirPort: spairport_wireless_card_type_wifi (0x14E4, 0x4387), wl0: Sep  3 2022 02:35:52 version 20.10.965.9.8.7.129 FWID 01-b0e84a9b
Bluetooth: Version (null), 0 services, 0 devices, 0 incoming serial ports
Network Service: Wi-Fi, AirPort, en0
USB Device: USB31Bus
USB Device: USB31Bus
USB Device: USB31Bus
Thunderbolt Bus: Laptop, Apple Inc.
Thunderbolt Bus: Laptop, Apple Inc.
Thunderbolt Bus: Laptop, Apple Inc.

<\details>

@svobs
Copy link
Contributor Author

svobs commented Dec 8, 2022

Oh that makes more sense 🙃 It was easy enough to sort the language entries which show up in the auto-complete popup.

However, I wasn't able to find a handle for the auto-complete popup itself anywhere, so I think we may have to live with the current width. From reading some forum posts, it looks like it is probably creating a child window, but there's just no hint about where it's doing that. If we wanted to customize it, we might be better off disabling the built-in autocomplete and just coding our own. (It might be a good long-term strategy to move away from NSTokenField in general. It's not efficient, and is very temperamental. Future support for it also seems dubious - Apple has deleted the example code for it, and there is at least one glaring bug in the API that has never been fixed.)

So far I've not been able to reproduce this again. I think I had the preferences window open with the list being displayed and then selected Quit from the IINA menu.

I wasn't able to reproduce it either. I agree - the stack trace seems to support your conclusion. Even without the infinite loop, the NSTokenField seems to spin its wheels for a while before it settles on a new state, and I'm guessing it received the shutdown signal in the middle of that and didn't like it. But again, I can't figure out how to get a handle for that. None of the public methods for NSTokenField are declared to throw exceptions. It looks like it's being thrown by some background layout process which is independent of the code we're working with.

Maybe it would be possible to reduce the likelihood of this happening by adding some small delay after all the windows are closed, and before IINA terminates. Although...I don't think we are actually closing the Settings window prior to termination, are we? Maybe we should start by doing that.

@low-batt
Copy link
Contributor

I pulled the latest commit and tested. I only found one problem. The user should be able to drag the codes around to change the priority order. That is now half working. I can drag the code at the end of the list to the left to the front of the list. But if I then try and drag that code from the front of the list right and put it back at the end of the list, I can move the token to the end of the list and it looks like it is going to work, but when I let go of the mouse button the code is not moved from the front of the list.

I did try hard to trigger a constraint error crash. It passed all my tests.

@svobs
Copy link
Contributor Author

svobs commented Dec 11, 2022

I pulled the latest commit and tested. I only found one problem. The user should be able to drag the codes around to change the priority order. That is now half working. I can drag the code at the end of the list to the left to the front of the list. But if I then try and drag that code from the front of the list right and put it back at the end of the list, I can move the token to the end of the list and it looks like it is going to work, but when I let go of the mouse button the code is not moved from the front of the list.

Surprisingly hard problem, given that I'm trying to do duplicate removal too. For drag & drop like this, even though it should be a "move", it's sending 2 notifications, as though it's first copying & pasting, and then doing a delete as a second transaction.

This, combined with the fact that I've begun doing the updates tracking in code, rather than trying to rely on the objectValue or stringValue from NSTextField, which has proven unreliable...

I came up with a quick & dirty diff on two CSV lists (the prev and new field entries), to guess which token was being copied, and remove that. It seems to work pretty well, except that because it's setting the objectValue the dropped token loses its highlight on the drop...

If that's too much of a compromise, I can remove duplicate detection entirely. Too many unknowns to figure this out more completely. I'm cuckoo from Cocoa Dev!

@low-batt
Copy link
Contributor

I'm confused by the explanation, as in I'm not understanding why dragging from the back to the front worked, and yet the other way didn't. No matter. I pulled the latest commit and could not break it. All seems good, but there are two new compilation warnings that need to be addressed:

/Users/low-batt/Documents/builds/pr-tests/iina/iina/LanguageTokenField.swift:161:9 Variable 'dictOld' was never mutated; consider changing to 'let' constant
/Users/low-batt/Documents/builds/pr-tests/iina/iina/LanguageTokenField.swift:162:9 Variable 'dictNew' was never mutated; consider changing to 'let' constant

It is really good to get issue #3505 fixed. Users have been reporting this for a long time. I think IINA should be putting a priority on making sure subtitle support is fully working as the ability to download subtitles is a very useful special feature that IINA provides. There still are a number of problems in this area of IINA. Fixing the UI for this preference is an important step in fixing subtitle support.

…ding from saved prefs. Disallow duplicate language entries. Sort autocomplete entries. Trim language tokens for whitespace & make lowercase.
@svobs
Copy link
Contributor Author

svobs commented Dec 12, 2022

I'm confused by the explanation, as in I'm not understanding why dragging from the back to the front worked, and yet the other way didn't.

It's because of the relatively sloppy way that NSTokenField notifies that a drag & drop has occurred.
Example sequence:

  1. self.stringValue = "A, B, C, D"
  2. {User drags B to the end}
  3. controlTextDidChange() notification! self.stringValue = "A, B, C, D, B"
  4. controlTextDidChange() notification! self.stringValue = "A, C, D, B"

What should be one notification instead shows up as two. Violates API best practices. But it's also not considered good practice for us to wait some arbitrary amount of time and try to guess which notification is the "final" one.

The code I wrote was already taking the first notification and treating it as the correct one, but it noticed it contained a duplicate token. And so the de-duplication code was too simple: it went through the string and saved the first occurrence of each token. By saving only the first occurrence, my code was setting self.stringValue = "A, B, C, D", which to the user looked like their drag to the right was ignored. Drags to the left would always be ok because it was saving the leftmost token. (And by saving the stringValue after the first notification (3), the second notification (4) now never happens).

So I had to come up with a solution which would look at the strings from (1) and (3) above, and try to figure out which B token in (3) was the dropped one, and keep that; and remove the other B. Kind of an interesting algorithmic puzzle.

But anyway... Fixed the warning. The latest version of XCode has a few new bugs (I'm back on an Intel Mac for now, if that matters). One of them is that warnings sometimes don't appear until I close the file and reopen it. ¯_(ツ)_/¯

It is really good to get issue #3505 fixed. Users have been reporting this for a long time.

There are big pieces of IINA which I don't use extensively, and although I generally check the newer issues as they're filed, I haven't waded through the backlog much; so I was unaware that such a prominent crasher existed. If there are other issues which you see as high-priority I'd be happy to take a look.

Lastly - this is a tangent but have you seen OpenAI's Whisper? I've been playing with it and it's incredible. At least for English. But makes me wonder whether downloading subtitles will even be necessary soon, if they can just be generated on-the-fly.

@low-batt
Copy link
Contributor

Thanks for the detailed explanation. All clear to me now.

Just finished testing on both macOS 13.0.1 and 10.15.7, all good.

There is one other crash I have been worried about. I'm pretty sure no one is looking into this one. It is another constraints related crash, but much more serious as IINA is crashing while animating the resizing of the main window. It was reported under macOS 11.5.2. Big Sur had issues. I don't know if the problem was tied to macOS 11. It did not reproduce for me. I did not have time to do a lot of testing. It is issue #3615. Let me know if you see something I didn't.

By the way are you using git commit --amend? The usual way I pull PR updates is failing:

low-batt@gag iina (pr4074)$ git pull origin pull/4074/head
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 4 (delta 2), reused 4 (delta 2), pack-reused 0
Unpacking objects: 100% (4/4), 4.23 KiB | 866.00 KiB/s, done.
From github.com:iina/iina
 * branch              refs/pull/4074/head -> FETCH_HEAD
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint: 
hint:   git config pull.rebase false  # merge
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint: 
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.
low-batt@gag iina (pr4074)$ 

I end up just starting from scratch to get the latest commit.

Copy link
Contributor

@low-batt low-batt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested under macOS 13.0.1 and 10.15.7. Changes look good to me.

@svobs
Copy link
Contributor Author

svobs commented Dec 12, 2022

I'll take a look at #3615.

By the way are you using git commit --amend?

Nope :) - I've been doing reset --soft & push --force. I will try using commit --amend - I've never considered it for anything other than changing the commit message! Although if you still need to deal with my "divergent" commits you can first do a git reset --hard HEAD~1 (or however many commits needed to get back to the commits which are in common) before pulling.

@low-batt
Copy link
Contributor

Definitely do not use --amend. That is considered bad to do for a published commit. I think what you want to do is to squash your commits.

@low-batt
Copy link
Contributor

There have been several requests for live subtitle generation. Issue #3867 is one of them. You will see I mentioned DeepSpeech as an example of a speech to text engine. This is definitely an area to investigate.

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

Successfully merging this pull request may close these issues.

Crash due to too many Update Constraints
3 participants