Skip to content

Commit

Permalink
Fix backgorund render crash and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
levinli303 committed Feb 24, 2021
1 parent a4065c9 commit f3cde59
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
12 changes: 7 additions & 5 deletions MobileCelestia.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1130;
LastUpgradeCheck = 1130;
LastUpgradeCheck = 1240;
ORGANIZATIONNAME = "Celestia Development Team";
TargetAttributes = {
979D2F7923FEB1A6005D2592 = {
Expand Down Expand Up @@ -954,6 +954,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down Expand Up @@ -983,8 +984,8 @@
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SHARED_BUILD_NUMBER = 85;
SHARED_BUILD_VERSION = 1.2.4;
SHARED_BUILD_NUMBER = 89;
SHARED_BUILD_VERSION = 1.2.6;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
Expand Down Expand Up @@ -1017,6 +1018,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand All @@ -1039,8 +1041,8 @@
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
SHARED_BUILD_NUMBER = 85;
SHARED_BUILD_VERSION = 1.2.4;
SHARED_BUILD_NUMBER = 89;
SHARED_BUILD_VERSION = 1.2.6;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
VALIDATE_PRODUCT = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1130"
LastUpgradeVersion = "1240"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
39 changes: 33 additions & 6 deletions MobileCelestia/Celestia/CelestiaDisplayController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ class CelestiaDisplayController: UIViewController {

// MARK: rendering
private var currentSize: CGSize = .zero
private var ready = false

private var isLoaded = false
private var isInBackground = false

private var isReady: Bool {
return isLoaded && !isInBackground
}

private var displayLink: CADisplayLink?
private var displaySource: DispatchSourceUserDataAdd?

Expand All @@ -47,25 +54,45 @@ class CelestiaDisplayController: UIViewController {
view = glView
}

override func viewDidLoad() {
super.viewDidLoad()

NotificationCenter.default.addObserver(self, selector: #selector(applicationWillResignActive), name: UIApplication.willResignActiveNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(applicationDidBecomeActive), name: UIApplication.didBecomeActiveNotification, object: nil)
}

override func viewSafeAreaInsetsDidChange() {
super.viewSafeAreaInsetsDidChange()

guard ready else { return }
guard isLoaded else { return }

core?.setSafeAreaInsets(view.safeAreaInsets.scale(by: glView.contentScaleFactor))
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)

guard ready else { return }
guard isLoaded else { return }

if previousTraitCollection?.displayScale != traitCollection.displayScale {
updateContentScale()
}
}
}

extension CelestiaDisplayController {
@objc private func applicationWillResignActive() {
if isReady {
CelestiaAppCore.finish()
}
isInBackground = true
}

@objc private func applicationDidBecomeActive() {
isInBackground = false
}
}

private extension CelestiaAppCore {
func setSafeAreaInsets(_ safeAreaInsets: UIEdgeInsets) {
setSafeAreaInsets(left: safeAreaInsets.left, top: safeAreaInsets.top, right: safeAreaInsets.right, bottom: safeAreaInsets.bottom)
Expand All @@ -75,7 +102,7 @@ private extension CelestiaAppCore {
#if USE_MGL
extension CelestiaDisplayController: MGLKViewDelegate {
func mglkView(_ view: MGLKView!, drawIn rect: CGRect) {
guard ready else { return }
guard isReady else { return }

let size = view.drawableSize
if size != currentSize {
Expand All @@ -90,7 +117,7 @@ extension CelestiaDisplayController: MGLKViewDelegate {
#else
extension CelestiaDisplayController: GLKViewDelegate {
func glkView(_ view: GLKView, drawIn rect: CGRect) {
guard ready else { return }
guard isReady else { return }

let size = CGSize(width: view.drawableWidth, height: view.drawableHeight)
if size != currentSize {
Expand Down Expand Up @@ -247,7 +274,7 @@ extension CelestiaDisplayController {

self.setupDisplayLink()

self.ready = true
self.isLoaded = true

completionHandler(.success(()))
})
Expand Down

0 comments on commit f3cde59

Please sign in to comment.