From a86a6367b5bbde1be711ccf887e17b48d0b53f7b Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 11 Feb 2017 12:58:47 -0500 Subject: [PATCH] Slightly shuffled to avoid a race condition on the best-effort updater. --- .../Documents/MachineDocument.swift | 24 +++++++++---------- .../Mac/Clock Signal/Views/CSOpenGLView.h | 2 +- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift index 0d946e3c2..995e35027 100644 --- a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift +++ b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift @@ -31,24 +31,14 @@ class MachineDocument: return NSSize(width: 4.0, height: 3.0) } - @IBOutlet weak var openGLView: CSOpenGLView! { - didSet { - openGLView.delegate = self - openGLView.responderDelegate = self - } - } - + @IBOutlet weak var openGLView: CSOpenGLView! @IBOutlet var optionsPanel: MachinePanel! @IBAction func showOptions(_ sender: AnyObject!) { optionsPanel?.setIsVisible(true) } fileprivate var audioQueue: CSAudioQueue! = nil - fileprivate lazy var bestEffortUpdater: CSBestEffortUpdater = { - let updater = CSBestEffortUpdater() - updater.delegate = self - return updater - }() + fileprivate var bestEffortUpdater: CSBestEffortUpdater! override var windowNibName: String? { return "MachineDocument" @@ -64,8 +54,16 @@ class MachineDocument: self.machine.setView(self.openGLView, aspectRatio: Float(displayAspectRatio.width / displayAspectRatio.height)) }) - setupClockRate() self.machine.delegate = self + self.bestEffortUpdater = CSBestEffortUpdater() + self.bestEffortUpdater.delegate = self + + // callbacks from the OpenGL may come on a different thread, immediately following the .delegate set; + // hence the full setup of the best-effort updater prior to setting self as a delegate + self.openGLView.delegate = self + self.openGLView.responderDelegate = self + + setupClockRate() self.optionsPanel?.establishStoredOptions() // bring OpenGL view-holding window on top of the options panel diff --git a/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.h b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.h index 9ecae793d..34d08584e 100644 --- a/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.h +++ b/OSBindings/Mac/Clock Signal/Views/CSOpenGLView.h @@ -53,7 +53,7 @@ */ @interface CSOpenGLView : NSOpenGLView -@property (nonatomic, weak, nullable) id delegate; +@property (atomic, weak, nullable) id delegate; @property (nonatomic, weak, nullable) id responderDelegate; /*!