From 252bed0e6be99cde99de952b236dbcb6f6632db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Je=CC=81re=CC=81my=20Marchand?= Date: Sun, 18 Mar 2018 12:55:54 +0100 Subject: [PATCH] FIX RemoteActionPositionController memory cycle --- Sources/RemoteActionPositionController.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/RemoteActionPositionController.swift b/Sources/RemoteActionPositionController.swift index 0107ca2..391fe96 100644 --- a/Sources/RemoteActionPositionController.swift +++ b/Sources/RemoteActionPositionController.swift @@ -59,6 +59,11 @@ class RemoteActionPositionController: NSObject, PositionController { private let gamePad = GCController.controllers().first?.microGamepad + // MARK: Deinit + deinit { + gamePad?.dpad.valueChangedHandler = nil + } + // MARK: State private var touchLocation: Location = .center { didSet { @@ -136,7 +141,7 @@ class RemoteActionPositionController: NSObject, PositionController { // MARK: Surface Touch private func trackSurfaceTouch() { gamePad?.reportsAbsoluteDpadValues = true - gamePad?.dpad.valueChangedHandler = { (dpad: GCControllerDirectionPad, xValue: Float, yValue: Float) -> Void in + gamePad?.dpad.valueChangedHandler = { [unowned self] (dpad: GCControllerDirectionPad, xValue: Float, yValue: Float) -> Void in if xValue > 0.5 { self.touchLocation = .right