2016-03-05 74 views
1

我用Swift和GameplayKit編寫了一個名爲「Spiral」的遊戲。但是當我的GKGridGraph實例釋放時,應用程序總是崩潰。這隻發生在iOS9.2上。我在iOS9.0上測試了我的代碼,一切都很順利。這裏是崩潰調用堆棧:GameplayKit - [GKGraph dealloc]:在iOS9.2上崩潰

#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) 
       } 
      } 
     } 
    } 
} 
+0

您是否嘗試過當前的iOS 9.3測試版? – rickster

+0

@rickster好主意!我希望這可以幫助我:) – YangXiaoyu

回答

1

正如@rickster說,它不會在iOS 9.3 beta6崩潰。

1

9.2中的GKGridGraph dealloc有一個bug。我向蘋果反饋說這是一個已知的bug。自從我發送給蘋果公司的測試用例開始工作以後,它顯然已經在9.3中修復了。

+0

是的,但我發現它泄漏在9.3 – YangXiaoyu