Skip to content

Commit ae9f4ba

Browse files
committed
Delay tab-switch to avoid deadlock
... not sure it actually does it. When switching tabs during activity, we (well, AppKit) sometimes deadlock. So instead dispatch the switch to the main-queue in the hope that resolves potential reentrancy issues.
1 parent 23f368e commit ae9f4ba

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Sources/swift-progress/WindowControllers/SPWindowController.m

+9-4
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,15 @@ - (void)stop:(id)_sender {
197197
- (void)switchTabs:(id)_sender {
198198
if (![_sender isKindOfClass:[NSToolbarItem class]])
199199
return;
200-
201-
NSToolbarItem *tbi = (__typeof(tbi))_sender;
202-
NSTabView *tv = tabVC.tabView;
203-
[tv selectTabViewItemWithIdentifier:tbi.itemIdentifier];
200+
201+
// I've seen a deadlock in NSViewHierarchyLock when
202+
// the tableview is updating while the tab is switched.
203+
// Hope this may easen the issue :->
204+
dispatch_async(dispatch_get_main_queue(), ^{
205+
NSToolbarItem *tbi = (__typeof(tbi))_sender;
206+
NSTabView *tv = tabVC.tabView;
207+
[tv selectTabViewItemWithIdentifier:tbi.itemIdentifier];
208+
});
204209
}
205210

206211
@end

0 commit comments

Comments
 (0)