【问题标题】:Sprite Kit game crashes on Game Over on tvOS 9.1 and iOS 9.2Sprite Kit 游戏在 tvOS 9.1 和 iOS 9.2 上的 Game Over 中崩溃
【发布时间】:2015-12-20 06:28:12
【问题描述】:

我的 Sprite Kit 游戏在游戏结束时崩溃。这发生在 tvOS 9.1 和 iOS 9.2 上。之前,我让它在 iOS 9.1 上运行而没有崩溃。

这似乎是一个 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

启用断点异常后,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
 }
}

【问题讨论】:

  • 我们可能需要更多代码。如果您认为这是一个框架错误,请提交雷达:radar.apple.com
  • 谢谢。但我不确定代码在哪里。它在 Game Over 时崩溃,所以我将在我的问题中添加该功能。
  • 您是否启用了异常中断?如果没有,请转到菜单 Debug > Breakpoints > Create Exception Breakpoint...
  • @0x141E 是的,当我启用异常断点时,它会在声音文件常量let soundHitLava = SKAction.playSoundFileNamed("DrownFireBug.mp3", waitForCompletion: false) 上崩溃我不知道为什么它会在那里崩溃,因为文件在捆绑包中。我会将错误添加到我的问题中。
  • 它看起来和this 一样的错误发生在 OP 向场景中添加发射器时。我猜这是一个操作系统错误。

标签: swift opengl-es sprite-kit tvos


【解决方案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,那么游戏就不会崩溃。我不知道为什么会发生这种情况,但 Apple 目前正在解决这个问题,并且被认为是一个错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-14
    • 1970-01-01
    • 2015-12-16
    相关资源
    最近更新 更多