ios - SpriteKit 动画因 validateIndexBuffer 而崩溃

标签 ios swift xcode sprite-kit skspritenode

我是 SpriteKit 世界的初学者,现在我正在通过 SKWarpGeometryGrid 制作动画。当我有大量 sourcePositions/destinationPositions 它填满了我的缓冲区,我遇到了下一次崩溃:validateIndexBuffer:131: failed assertion `indexBufferOffset(0) + (indexCount(4704) * 2) must be <= indexBuffer length.'

Sprite Kit app crashes when run on real device and plugged into computer

这个答案很有帮助,现在没有崩溃,但动画停止工作,图像不时从屏幕上消失。

调试器说了什么:

2018-06-07 14:27:27.102269+0300 LiveGram[15259:5348410] Execution of the command buffer was aborted due to an error during execution. Discarded (victim of GPU error/recovery) (IOAF code 5) 2018-06-07 14:27:27.102352+0300 LiveGram[15259:5348410] Execution of the command buffer was aborted due to an error during execution. Caused GPU Hang Error (IOAF code 3) 2018-06-07 14:27:27.102389+0300 LiveGram[15259:5348410] Execution of the command buffer was aborted due to an error during execution. Discarded (victim of GPU error/recovery) (IOAF code 5) 2018-06-07 14:27:27.156201+0300 LiveGram[15259:5348410] Execution of the command buffer was aborted due to an error during execution. Discarded (victim of GPU error/recovery) (IOAF code 5) 2018-06-07 14:27:27.156278+0300 LiveGram[15259:5348410] Execution of the command buffer was aborted due to an error during execution. Caused GPU Hang Error (IOAF code 3) 2018-06-07 14:27:27.156311+0300 LiveGram[15259:5348410] Execution of the command buffer was aborted due to an error during execution. Discarded (victim of GPU error/recovery) (IOAF code 5) 2018-06-07 14:27:27.158508+0300 LiveGram[15259:5348408] Execution of the command buffer was aborted due to an error during execution. Ignored (for causing prior/excessive GPU errors) (IOAF code 4) 2018-06-07 14:27:27.158586+0300 LiveGram[15259:5348408] Execution of the command buffer was aborted due to an error during execution. Ignored (for causing prior/excessive GPU errors) (IOAF code 4) 2018-06-07 14:27:27.158613+0300 LiveGram[15259:5348408] Execution of the command buffer was aborted due to an error during execution. Ignored (for causing prior/excessive GPU errors) (IOAF code 4)

有人知道我做错了什么吗?我该如何解决?

最佳答案

我遇到了这种类型的问题并且刚刚解决了它。当您为硬件分配过多工作而 GPU 无法如此快速地处理它时,就会发生这种情况。

你可以做些什么来避免崩溃: 在 Xcode 中: 1.Command+Option+R 2.选项标签 3.将Metal API验证设置为禁用

它应该可以防止应用程序崩溃,但问题仍然存在。

您接下来可以做的是搜索您的代码以了解问题的确切位置。我是这样做的:

注释部分代码并运行应用程序以查看错误是否仍然存在,如下所示:

/* //Put this at the beginning

CODE
.
.
.
CODE
*/    //This at the end 

如果错误仍然存​​在,请取消注释这部分代码并注释下一段代码,一直这样做直到您不再有问题为止。然后你将继续评论你的代码,但在问题部分的小部分,直到你找到到底是什么导致了它。 当您

addChild(This one needs hard GPU processing)

在我的例子中,我添加了一个 LightNode。我的解决方案是创建一个 SKAction:

let action =  SKAction.wait(forDuration: 1) //Try different time durations
scene.run(action, completion:
{
code that is causing the problem

})

通过这种方式,您可以分散所需的处理能力并中断硬件。

希望对您有所帮助!

关于ios - SpriteKit 动画因 validateIndexBuffer 而崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50740420/

相关文章:

javascript - iPad/iPhone 设备上的 HTML5 音频在被触摸时停止

ios - 如何使动画 subview 中的按钮在该 subview 移动期间起作用?

ios - 核心数据迁移 - 从先前版本迁移选定的数据

ios - 一些 Restkit 方法不可用

Swift:与 Realm 的嵌套通用辅助函数相关的问题

xcode - 在 Xcode 中使用 NSTask 在 AppKit 应用程序中运行时,Rust 1.4.0(或更高版本)cargo/rustc 崩溃

iphone - 保存图像供以后在 iPhone 中使用

ios - 在 Swift 中将 TextField Delegate 设置为 ViewController 中的另一个类不起作用

swift - 使用 Apples CryptoKit 在 iOS 和 Kotlin/Java 之间进行跨平台 AES 加密

ios - 在 iPad 上运行时,iPhone 应用程序 View 在底部被切断