Skip to content

Commit

Permalink
fix: crash in very rare data-race
Browse files Browse the repository at this point in the history
Most common crash in AppCenter for v6.12.0:
closure #1 () -> () in static AltTab.Windows.refreshThumbnailsAsync(__C.NSScreen, Swift.Int) -> ()
  • Loading branch information
lwouis committed Feb 1, 2021
1 parent b02e8be commit e9e61af
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/logic/Windows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit e9e61af

Please sign in to comment.