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) -> ()
This commit is contained in:
Louis Pontoise
2021-02-02 01:55:26 +09:00
committed by lwouis
parent b02e8be802
commit e9e61afc6a
+16 -14
View File
@@ -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)
}
}
}