Sprite Kit game crashes on Game Over on tvOS 9.1 and iOS 9.2

自作多情 提交于 2020-01-02 16:14:49

问题


I have a Sprite Kit game that is crashing when the game is over. This happening on the tvOS 9.1 and iOS 9.2. Before, I had it running on iOS 9.1 without crashing.

It seems to be an OpenGL issue, but when I search the function in Xcode, it doesn't come up with anything.

Unfortunately, the error is not consistent in appearing in the console. Here's the error:

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 also points to the AppDelate class when it crashes:

class AppDelegate: UIResponder, UIApplicationDelegate

With breakpoint exception enabled, Xcode points to this line. It's a constant for a sound file:

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

More info from the exception breakpoint:

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

Here's the GameOver function in the GameScene:

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

And here is the GameOver class:

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

回答1:


The answer I found out was to lower the SKEmitterNode birthrate and particles to emit as this would cause the game to crash.

In the 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)

   ....
 }

Once lowered to 50 respectively, then the game wouldn't crash. I don't know why this is happening, but Apple is currently working on this and is considered a bug.



来源:https://stackoverflow.com/questions/34378530/sprite-kit-game-crashes-on-game-over-on-tvos-9-1-and-ios-9-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!