Leaks using GKStateMachine in GameplayKit

I'm having leak problems using GKStateMachine. My application is pretty simple code to check the problem. This is GameScene:

import SpriteKit
import GameplayKit

class GameScene: SKScene {

   lazy var gameState:GKStateMachine = GKStateMachine(states: [Introduction(scene: self)])

   override func didMove(to view: SKView) {

      self.gameState.enter(Introduction.self)
   }
} 

And this is my condition:

import SpriteKit
import GameplayKit

class Introduction: GKState {

   unowned let scene:GameScene

   init(scene:SKScene) {
      self.scene = scene as! GameScene
      super.init()
   }

   override func didEnter(from previousState: GKState?) {
      print("INSIDE THE Introduction STATE")
   }
}

The problem is that when I run the Leaks debugger, I got one leak as soon as I enter the state. Does anyone have a suggestion?

+4
source share
1 answer

You can simplify the constructor to avoid type casting.

init(scene: GameScene) {
  self.scene = scene
  super.init()
}
0
source

Source: https://habr.com/ru/post/1666415/


All Articles