SpriteKit - SKTexture PreloadTextures EXC_BAD_ACCESS崩溃

时间:2014-12-09 18:33:16

标签: ios sprite-kit textures exc-bad-access

我正在尝试预加载纹理。当我预加载完整的SKTextureAtlas时,我的代码运行正常。但是当我尝试预加载SKTextures时,我收到一个EXC_BAD_ACCESS错误。这是我的代码:

[SKTexture preloadTextures:@[@"steady_beat-animation-shark_4"] withCompletionHandler:blah, blah];

无论我输入什么纹理,输入了多少,或者我在哪里调用此代码(在SKSceneSKSpriteNode中),我都会收到EXC_BAD_ACCESS错误。

错误是:

objc_msgSend
Thread 4: EXC_BAD_ACCESS (code=1, address=0x1f)

以下是调用堆栈符号,如果它有用:

(lldb) po [NSThread callStackSymbols]
<_NSCallStackArray 0x16f738f0>(
0   ???                                 0x038a8b74 0x0 + 59411316,
1   Edify-Testing-Debug                 0x000c9d89 main + 0,
2   libdispatch.dylib                   0x0068cad3 _dispatch_call_block_and_release + 10,
3   libdispatch.dylib                   0x006967c5 _dispatch_root_queue_drain + 968,
4   libdispatch.dylib                   0x00697885 _dispatch_worker_thread3 + 108,
5   libsystem_pthread.dylib             0x32301e25 _pthread_wqthread + 668,
6   libsystem_pthread.dylib             0x32301b78 start_wqthread + 8
)

1 个答案:

答案 0 :(得分:3)

SKTexture preloadTextures:需要NSArray SKTextures,而非NSString

https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKTexture_Ref/index.html#//apple_ref/occ/clm/SKTexture/preloadTextures:withCompletionHandler

[SKTexture preloadTextures:@[[SKTexture textureWithImageNamed:@"steady_beat-animation-shark_4"]] withCompletionHandler:blah, blah];