From 0ad81bb5dfbad70a02ad09b500e381cfccc61f80 Mon Sep 17 00:00:00 2001 From: Louis Pontoise Date: Tue, 2 Feb 2021 00:47:06 +0900 Subject: [PATCH] fix: crash in very rare data-race Most common crash in AppCenter for v6.12.0: closure #1 () -> () in static AltTab.Windows.refreshThumbnailsAsync(__C.NSScreen, Swift.Int) -> () --- src/logic/Windows.swift | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/logic/Windows.swift b/src/logic/Windows.swift index fbffe5331..a0f97f0b0 100644 --- a/src/logic/Windows.swift +++ b/src/logic/Windows.swift @@ -158,23 +158,25 @@ class Windows { } static func refreshThumbnailsAsync(_ screen: NSScreen, _ currentIndex: Int = criticalFirstThumbnails) { - if !App.app.appIsBeingUsed || Preferences.hideThumbnails { return } - BackgroundWork.mainQueueConcurrentWorkQueue.async { - if currentIndex < list.count { - let window = list[currentIndex] - if window.shouldShowTheUser { - window.refreshThumbnail() - DispatchQueue.main.async { - let view = ThumbnailsView.recycledViews[currentIndex] - if view.thumbnail.image != window.thumbnail { - let oldSize = view.thumbnail.frame.size - view.thumbnail.image = window.thumbnail - view.thumbnail.image?.size = oldSize - view.thumbnail.frame.size = oldSize + DispatchQueue.main.async { + if !App.app.appIsBeingUsed || Preferences.hideThumbnails { return } + BackgroundWork.mainQueueConcurrentWorkQueue.async { + if currentIndex < list.count { + let window = list[currentIndex] + if window.shouldShowTheUser { + window.refreshThumbnail() + DispatchQueue.main.async { + let view = ThumbnailsView.recycledViews[currentIndex] + if view.thumbnail.image != window.thumbnail { + let oldSize = view.thumbnail.frame.size + view.thumbnail.image = window.thumbnail + view.thumbnail.image?.size = oldSize + view.thumbnail.frame.size = oldSize + } } } + refreshThumbnailsAsync(screen, currentIndex + 1) } - refreshThumbnailsAsync(screen, currentIndex + 1) } } }