GameplayKit -[GKGraph dealloc]: сбой на iOS9.2
Я написал игру под названием "Спираль" со Swift и GameplayKit. Но когда мой GKGridGraph
экземпляр dealloc, приложение всегда вылетает. Это происходит только на iOS9.2. Я тестировал свой код на iOS9.0, все было в порядке. Вот стек вызовов вызовов:
#0 0x0000000112e2546f in objc_loadWeakRetained ()
#1 0x000000011157ed38 in GKCGridGraph::~GKCGridGraph() ()
#2 0x000000011157ee4e in GKCGridGraph::~GKCGridGraph() ()
#3 0x000000011157c07e in -[GKGraph dealloc] ()
#4 0x0000000112e25afe in objc_object::sidetable_release(bool) ()
#5 0x000000010efa094a in @objc MazeMap.__ivar_destroyer ()
#6 0x0000000112e107bb in object_cxxDestructFromClass(objc_object*, objc_class*) ()
#7 0x0000000112e1b390 in objc_destructInstance ()
#8 0x0000000112e1b3c3 in object_dispose ()
#9 0x0000000111ac3d4d in -[UIResponder dealloc] ()
#10 0x0000000111713426 in -[SKNode dealloc] ()
#11 0x0000000112e25afe in objc_object::sidetable_release(bool) ()
#12 0x000000010ef8136a in @objc PlayerControlComponent.__ivar_destroyer ()
#13 0x0000000112e107bb in object_cxxDestructFromClass(objc_object*, objc_class*) ()
#14 0x0000000112e1b390 in objc_destructInstance ()
#15 0x0000000112e1b3c3 in object_dispose ()
#16 0x0000000112e25afe in objc_object::sidetable_release(bool) ()
#17 0x00000001109078c8 in -[__NSArrayI dealloc] ()
#18 0x0000000112e25afe in objc_object::sidetable_release(bool) ()
#19 0x0000000112e260b8 in (anonymous namespace)::AutoreleasePoolPage::pop(void*) ()
#20 0x00000001153489ef in CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) ()
#21 0x000000011097ac84 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
#22 0x000000011097a831 in __CFRunLoopDoTimer ()
#23 0x000000011093c241 in __CFRunLoopRun ()
#24 0x000000011093b828 in CFRunLoopRunSpecific ()
#25 0x0000000115916ad2 in GSEventRunModal ()
#26 0x00000001118b6610 in UIApplicationMain ()
#27 0x000000010ef918ad in main at /Users/yangxiaoyu/Documents/Code/Spiral/Spiral/AppDelegate.swift:16
#28 0x0000000113cbe92d in start ()
#29 0x0000000113cbe92d in start ()
я использую GKGridGraph
в моем MazeModeScene
учебный класс:
private let MazeWidth: Int32 = 33
private let MazeHeight: Int32 = 33
private func tileAtRow(row: Int32, column col: Int32) -> TileType {
return TileType(rawValue: Maze[Int(row * MazeWidth + col)]) ?? .None
}
class MazeMap: SKNode {
let width = MazeWidth
let height = MazeHeight
let pathfindingGraph: GKGridGraph = GKGridGraph(fromGridStartingAt: vector_int2(0, 0), width: MazeWidth, height: MazeHeight, diagonalsAllowed: false)
var startPosition: GKGridGraphNode
let shapeStartPositions: [GKGridGraphNode]
init(size: CGSize) {
var walls = [GKGridGraphNode]()
var spawnPoints = [GKGridGraphNode]()
startPosition = GKGridGraphNode(gridPosition: vector_int2(0, 0))
for j in 0 ..< height {
for i in 0 ..< width {
let tile = tileAtRow(height - 1 - j, column: i)
switch tile {
case .Wall:
if let wall = pathfindingGraph.nodeAtGridPosition(vector_int2(i, j)) {
walls.append(wall)
}
case .Portal:
if let portal = pathfindingGraph.nodeAtGridPosition(vector_int2(i, j)) {
spawnPoints.append(portal)
}
case .Start:
startPosition = pathfindingGraph.nodeAtGridPosition(vector_int2(i, j))!
default:
break
}
}
}
pathfindingGraph.removeNodes(walls)
shapeStartPositions = spawnPoints
super.init()
addMagicRoads()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func pointForGridPosition(position: vector_int2) -> CGPoint {
let center = CGPoint(x: UIScreen.mainScreen().bounds.midX, y: UIScreen.mainScreen().bounds.midY)
let deltaX = (position.x - MazeWidth / 2) * mazeCellWidth
let deltaY = (position.y - MazeHeight / 2) * mazeCellWidth
return CGPoint(x: center.x + deltaX , y: center.y + deltaY)
}
func addMagicRoads() {
// Generate maze.
let graph = pathfindingGraph
for j in 0 ..< height {
for i in 0 ..< width {
if graph.nodeAtGridPosition(vector_int2(i, j)) != nil {
let node = MagicRoad(graph: graph, position: vector_int2(i, j))
node.position = pointForGridPosition(vector_int2(i, j))
addChild(node)
}
}
}
}
}
2 ответа
В 9.2 есть ошибка в GKGridGraph dealloc. Я сообщил об этом Apple, которая ответила, что это известная ошибка. Очевидно, это было исправлено в 9.3, так как тестовый пример, который я отправил в Apple, теперь работает.