From 9e66df0ace11f70969f8bfd9d1e8bf8c8eb6effe Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Fri, 12 Aug 2016 13:12:48 -0500 Subject: [PATCH] Fixes crash when backgrounding app before starting a game --- Delta/Emulation/GameViewController.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Delta/Emulation/GameViewController.swift b/Delta/Emulation/GameViewController.swift index ba1813e..2e76960 100644 --- a/Delta/Emulation/GameViewController.swift +++ b/Delta/Emulation/GameViewController.swift @@ -367,7 +367,10 @@ private extension GameViewController extension GameViewController: SaveStatesViewControllerDelegate { private func updateAutoSaveState() - { + { + // Ensures game is non-nil and also a Game subclass + guard let game = self.game as? Game else { return } + // If pausedSaveState exists and has already been saved, don't update auto save state // This prevents us from filling our auto save state slots with the same save state let savedPausedSaveState = self.pausedSaveState?.isSaved ?? false @@ -379,7 +382,7 @@ extension GameViewController: SaveStatesViewControllerDelegate let backgroundContext = DatabaseManager.shared.newBackgroundContext() backgroundContext.performAndWait { - let game = backgroundContext.object(with: (self.game as! Game).objectID) as! Game + let game = backgroundContext.object(with: game.objectID) as! Game let predicate = NSPredicate(format: "%K == %d AND %K == %@", #keyPath(SaveState.type), SaveStateType.auto.rawValue, #keyPath(SaveState.game), game)