2015-12-20 135 views
2

我有一個Sprite Kit遊戲,當遊戲結束時會崩潰。這發生在tvOS 9.1和iOS 9.2上。之前,我在iOS 9.1上運行時沒有崩潰。Sprite Kit遊戲在tvOS 9.1和iOS 9.2上游戲崩潰

它似乎是一個OpenGL的問題,但是當我在Xcode中搜索函數時,它沒有提供任何東西。

不幸的是,出現在控制檯中的錯誤並不一致。這裏的錯誤:

Jet: draw_indexed: indexType must be 'unsigned_int' or 'unsigned_short' 
Assertion failed: (indexType == jet_component_type_unsigned_int || indexType 
== jet_component_type_unsigned_short), function draw_indexed, file 
/BuildRoot/Library/Caches/com.apple.xbs/Sources/Jet_Sim/Jet- 
1.50.1/Jet/jet_context_OpenGL.mm, line 1426. 

Xcode中還指出,AppDelate類時崩潰:

class AppDelegate: UIResponder, UIApplicationDelegate

enter image description here

啓用斷點例外,Xcode中指向此行。這是一個聲音文件的常數:

let soundHitLava = SKAction.playSoundFileNamed("DrownFireBug.mp3", 
waitForCompletion: false) 

從異常斷點更多信息:

SpriteKit`+[SKAction(SKActions) playSoundFileNamed:waitForCompletion:]: 
    0x10b95e738 <+0>: pushq %rbp 
    0x10b95e739 <+1>: movq %rsp, %rbp 
    0x10b95e73c <+4>: movq 0x15bf8d(%rip), %rdi  ; (void *)0x000000010babd020: SKPlaySound 
    0x10b95e743 <+11>: movq 0x1618b6(%rip), %rax  ; (void *)0x000000010b412be8: CGPointZero 
    0x10b95e74a <+18>: movsd (%rax), %xmm0 
    0x10b95e74e <+22>: movsd 0x8(%rax), %xmm1 
    0x10b95e753 <+27>: movq 0x159a46(%rip), %rsi  ; "playSoundFileNamed:atPosition:waitForCompletion:" 
    0x10b95e75a <+34>: movzbl %cl, %ecx 
    0x10b95e75d <+37>: callq *0x1619a5(%rip)   ; (void *)0x000000010d09e800: objc_msgSend 
    0x10b95e763 <+43>: movq %rax, %rdi 
    0x10b95e766 <+46>: callq 0x10ba192e8    ; symbol stub for: objc_retainAutoreleasedReturnValue 
    0x10b95e76b <+51>: movq %rax, %rdi // **Thread 1: Breakpoint 1.2 
    0x10b95e76e <+54>: popq %rbp 
    0x10b95e76f <+55>: jmp 0x10ba1929a    ; symbol stub for: objc_autoreleaseReturnValue 

這裏是在GameScene的GAMEOVER功能:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { 

    #if os(tvOS) // tvOS 
    if startTouchX == 0.0 { 
     startTouchX = (touches.first?.locationInNode(self).x)! 
    } 
    #endif 

    switch gameState.currentState { 
    case is WaitingForTap: 
    gameState.enterState(WaitingForBomb) 
    // Switch to playing state 
    self.runAction(SKAction.waitForDuration(2.0), 
     completion:{ 
     self.gameState.enterState(Playing) 
    }) 

    case is GameOver: 
    let newScene = GameScene(fileNamed:"GameScene") 
    newScene!.scaleMode = .AspectFill 
    let reveal = SKTransition.flipHorizontalWithDuration(0.5) 
    self.view?.presentScene(newScene!, transition: reveal) 

    self.saveHighScore("com.prismstudios.jumpingcarl.leaderboard", score: GameState.sharedInstance.highScore) 

    GameState.sharedInstance.highScore = 0 
    GameState.sharedInstance.coins = 0 

    default: 
     break 
    } 
    } 

這裏是GAMEOVER類:

import SpriteKit 
import GameplayKit 

class GameOver: GKState { 
    unowned let scene: GameScene 

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

override func didEnterWithPreviousState(previousState: GKState?) { 
if previousState is Playing { 

    scene.playBackgroundMusic("SpaceGame.caf") 
    let gameOver = SKSpriteNode(imageNamed: "GameOver") 
    gameOver.position = scene.getCameraPosition() 
    gameOver.zPosition = 10 
    scene.addChild(gameOver) 

    let explosion = scene.explosion(6.0) 
    explosion.position = gameOver.position 
    explosion.zPosition = 11 
    scene.addChild(explosion) 
    scene.runAction(scene.soundExplosions[3]) 
    scene.screenShakeByAmt(200) 

    scene.addChild(button) 
    } 
} 

override func isValidNextState(stateClass: AnyClass) -> Bool { 
    return stateClass is WaitingForTap.Type 
} 
} 
+0

我們可能需要更多的代碼。如果您認爲這是一個框架錯誤,請提供雷達:http://radar.apple.com –

+0

謝謝。但我不確定代碼中的位置。它在Game Over上崩潰,所以我會在我的問題中添加該函數。 – Paul

+1

@Mr_Pouet更新! – Paul

回答

1

我發現的答案是降低SKEmitterNode的出生率和粒子排放,因爲這會導致遊戲崩潰。

在GameScene.swift:

func explosion(intensity: CGFloat) -> SKEmitterNode { 
    let emitter = SKEmitterNode() 
    let particleTexture = SKTexture(imageNamed: "spark") 

    emitter.zPosition = 2 
    emitter.particleTexture = particleTexture 

    //LOWER the particleBirthRate and numParticlesToEmit 
    emitter.particleBirthRate = 50; //4000 * intensity 
    emitter.numParticlesToEmit = 50; //Int(400 * intensity) 

    .... 
} 

分別一旦降低到50,那麼遊戲將不會崩潰。我不知道爲什麼會發生這種情況,但蘋果目前正在研究這個問題,並被認爲是一個錯誤。