我用Swift和GameplayKit写了一个名为“Spiral”的游戏。但是当我的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)
}
}
}
}
}
答案 0 :(得分:1)
正如@rickster所说,它在iOS 9.3 beta6上并没有崩溃。
答案 1 :(得分:1)
9.2中的GKGridGraph dealloc中存在错误。我向苹果公司报告过,它回复说这是一个已知的错误。由于我发送给Apple的测试用例现在有效,因此显然已经修复了9.3。