From 05d483bc5b00f7d7fa29baccb6993fc29289fce8 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 2 Mar 2019 23:17:31 -0500 Subject: [PATCH] Corrects potential machine shutdown race condition. --- .../Documents/MachineDocument.swift | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift index c337449f8..733701706 100644 --- a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift +++ b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift @@ -199,23 +199,23 @@ class MachineDocument: // MARK: CSOpenGLViewDelegate final func openGLViewRedraw(_ view: CSOpenGLView, event redrawEvent: CSOpenGLViewRedrawEvent) { - if let machine = self.machine { - switch redrawEvent { - case .timer: - bestEffortLock.lock() - if let bestEffortUpdater = bestEffortUpdater { - bestEffortLock.unlock() - bestEffortUpdater.update() - } else { - bestEffortLock.unlock() - } - machine.updateView(forPixelSize: view.backingSize) - fallthrough - - case .appKit: - machine.drawView(forPixelSize: view.backingSize) + if redrawEvent == .timer { + bestEffortLock.lock() + if let bestEffortUpdater = bestEffortUpdater { + bestEffortLock.unlock() + bestEffortUpdater.update() + } else { + bestEffortLock.unlock() } } + + if drawLock.try() { + if redrawEvent == .timer { + machine.updateView(forPixelSize: view.backingSize) + } + machine.drawView(forPixelSize: view.backingSize) + drawLock.unlock() + } } // MARK: Runtime media insertion.