gpt4 book ai didi

ios - GameplayKit-[GKGraph dealloc] : crash on iOS9. 2

转载 作者:搜寻专家 更新时间:2023-11-01 07:26:26 26 4
gpt4 key购买 nike

我用 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 ()

我在我的 MazeModeScene 类中使用 GKGridGraph:

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)
}
}
}
}
}

最佳答案

正如@rickster 所说,它不会在 iOS 9.3 beta6 上崩溃。

关于ios - GameplayKit-[GKGraph dealloc] : crash on iOS9. 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35811432/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com