我知道有很多这样的问题,所以我尽量提供尽可能多的细节。我有用SpriteKit和几个场景开发的游戏。当我从一个场景转换到另一个场景时,我得到EXC_BAD_ACCESS (code = 1, address = 0x0)
。
bt
我有这个:
(lldb) bt
* thread #1: tid = 0x70119f, 0x0000000107e173b0 libsystem_platform.dylib`_platform_memmove$VARIANT$Nehalem + 112, queue = 'com.apple.spritekit.renderQueue', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
frame #0: 0x0000000107e173b0 libsystem_platform.dylib`_platform_memmove$VARIANT$Nehalem + 112
frame #1: 0x0000000103c4ce8c SpriteKit`SKCRenderer::preprocessSpriteImp(std::__1::vector<SKCRenderer::SpriteRenderInfo, std::__1::allocator<SKCRenderer::SpriteRenderInfo> >&, SKRenderQuadPool&, SKCSprite const*, _GLKMatrix4 const&, float, unsigned int&, bool) + 1156
frame #2: 0x0000000103c4d9a9 SpriteKit`SKCRenderer::preprocessSpriteImp(std::__1::vector<SKCRenderer::SpriteRenderInfo, std::__1::allocator<SKCRenderer::SpriteRenderInfo> >&, SKRenderQuadPool&, SKCSprite const*, _GLKMatrix4 const&, float, unsigned int&, bool) + 4001
frame #3: 0x0000000103c4d9a9 SpriteKit`SKCRenderer::preprocessSpriteImp(std::__1::vector<SKCRenderer::SpriteRenderInfo, std::__1::allocator<SKCRenderer::SpriteRenderInfo> >&, SKRenderQuadPool&, SKCSprite const*, _GLKMatrix4 const&, float, unsigned int&, bool) + 4001
frame #4: 0x0000000103c4d9a9 SpriteKit`SKCRenderer::preprocessSpriteImp(std::__1::vector<SKCRenderer::SpriteRenderInfo, std::__1::allocator<SKCRenderer::SpriteRenderInfo> >&, SKRenderQuadPool&, SKCSprite const*, _GLKMatrix4 const&, float, unsigned int&, bool) + 4001
frame #5: 0x0000000103c46da1 SpriteKit`SKCRenderer::preprocessAndSubmitSpriteInternal(std::__1::vector<SKCRenderer::SpriteRenderInfo const*, std::__1::allocator<SKCRenderer::SpriteRenderInfo const*> >&, std::__1::vector<SKCRenderer::SpriteRenderInfo, std::__1::allocator<SKCRenderer::SpriteRenderInfo> >&, SKRenderQuadPool&, SKCSprite const*, _GLKMatrix4 const&) + 139
frame #6: 0x0000000103c4a951 SpriteKit`SKCRenderer::submitScene(SKScene*, bool) + 393
frame #7: 0x0000000103c4853c SpriteKit`SKCRenderer::renderTransition(SKScene*, SKScene*, float) + 952
frame #8: 0x0000000103be6ece SpriteKit`-[SKView _renderContent] + 847
frame #9: 0x0000000107abd614 libdispatch.dylib`_dispatch_client_callout + 8
frame #10: 0x0000000107aa3002 libdispatch.dylib`_dispatch_barrier_sync_f_invoke + 365
frame #11: 0x0000000103be6a80 SpriteKit`-[SKView renderContent] + 96
frame #12: 0x0000000103be3a61 SpriteKit`__29-[SKView setUpRenderCallback]_block_invoke + 56
frame #13: 0x0000000103c0f744 SpriteKit`-[SKDisplayLink _callbackForNextFrame:] + 256
frame #14: 0x00000001068a310f QuartzCore`CA::Display::DisplayLinkItem::dispatch() + 37
frame #15: 0x00000001068a2fd7 QuartzCore`CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 315
frame #16: 0x0000000102f9c174 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
frame #17: 0x0000000102f9bd35 CoreFoundation`__CFRunLoopDoTimer + 1045
frame #18: 0x0000000102f5dd3d CoreFoundation`__CFRunLoopRun + 1901
frame #19: 0x0000000102f5d366 CoreFoundation`CFRunLoopRunSpecific + 470
frame #20: 0x0000000106e88a3e GraphicsServices`GSEventRunModal + 161
frame #21: 0x0000000103d808c0 UIKit`UIApplicationMain + 1282
* frame #22: 0x0000000102a0628d MemoryGame`main + 109 at AppDelegate.swift:15
frame #23: 0x0000000107af1145 libdyld.dylib`start + 1
(lldb)
也许这很重要:在下一个场景didMoveToView
中我预加载纹理(几个地图集)。
更新#1
我启用了地址清理程序,现在它在内部崩溃了:
(lldb) bt
* thread #1: tid = 0x705cf2, 0x000000010e36c0b0 libclang_rt.asan_iossim_dynamic.dylib`__sanitizer::internal_memmove(void*, void const*, unsigned long) + 320, queue = 'com.apple.spritekit.renderQueue', stop reason = EXC_BAD_ACCESS (code=1, address=0x460)
* frame #0: 0x000000010e36c0b0 libclang_rt.asan_iossim_dynamic.dylib`__sanitizer::internal_memmove(void*, void const*, unsigned long) + 320
frame #1: 0x000000010e3505a7 libclang_rt.asan_iossim_dynamic.dylib`wrap_memcpy + 1095
frame #2: 0x0000000110119e8c SpriteKit`SKCRenderer::preprocessSpriteImp(std::__1::vector<SKCRenderer::SpriteRenderInfo, std::__1::allocator<SKCRenderer::SpriteRenderInfo> >&, SKRenderQuadPool&, SKCSprite const*, _GLKMatrix4 const&, float, unsigned int&, bool) + 1156
frame #3: 0x000000011011a9a9 SpriteKit`SKCRenderer::preprocessSpriteImp(std::__1::vector<SKCRenderer::SpriteRenderInfo, std::__1::allocator<SKCRenderer::SpriteRenderInfo> >&, SKRenderQuadPool&, SKCSprite const*, _GLKMatrix4 const&, float, unsigned int&, bool) + 4001
frame #4: 0x000000011011a9a9 SpriteKit`SKCRenderer::preprocessSpriteImp(std::__1::vector<SKCRenderer::SpriteRenderInfo, std::__1::allocator<SKCRenderer::SpriteRenderInfo> >&, SKRenderQuadPool&, SKCSprite const*, _GLKMatrix4 const&, float, unsigned int&, bool) + 4001
frame #5: 0x000000011011a9a9 SpriteKit`SKCRenderer::preprocessSpriteImp(std::__1::vector<SKCRenderer::SpriteRenderInfo, std::__1::allocator<SKCRenderer::SpriteRenderInfo> >&, SKRenderQuadPool&, SKCSprite const*, _GLKMatrix4 const&, float, unsigned int&, bool) + 4001
frame #6: 0x0000000110113da1 SpriteKit`SKCRenderer::preprocessAndSubmitSpriteInternal(std::__1::vector<SKCRenderer::SpriteRenderInfo const*, std::__1::allocator<SKCRenderer::SpriteRenderInfo const*> >&, std::__1::vector<SKCRenderer::SpriteRenderInfo, std::__1::allocator<SKCRenderer::SpriteRenderInfo> >&, SKRenderQuadPool&, SKCSprite const*, _GLKMatrix4 const&) + 139
frame #7: 0x0000000110117951 SpriteKit`SKCRenderer::submitScene(SKScene*, bool) + 393
frame #8: 0x000000011011553c SpriteKit`SKCRenderer::renderTransition(SKScene*, SKScene*, float) + 952
frame #9: 0x00000001100b3ece SpriteKit`-[SKView _renderContent] + 847
frame #10: 0x0000000113f8a614 libdispatch.dylib`_dispatch_client_callout + 8
frame #11: 0x0000000113f70002 libdispatch.dylib`_dispatch_barrier_sync_f_invoke + 365
frame #12: 0x00000001100b3a80 SpriteKit`-[SKView renderContent] + 96
frame #13: 0x00000001100b0a61 SpriteKit`__29-[SKView setUpRenderCallback]_block_invoke + 56
frame #14: 0x00000001100dc744 SpriteKit`-[SKDisplayLink _callbackForNextFrame:] + 256
frame #15: 0x0000000112d7010f QuartzCore`CA::Display::DisplayLinkItem::dispatch() + 37
frame #16: 0x0000000112d6ffd7 QuartzCore`CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 315
frame #17: 0x000000010f469174 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
frame #18: 0x000000010f468d35 CoreFoundation`__CFRunLoopDoTimer + 1045
frame #19: 0x000000010f42ad3d CoreFoundation`__CFRunLoopRun + 1901
frame #20: 0x000000010f42a366 CoreFoundation`CFRunLoopRunSpecific + 470
frame #21: 0x0000000113355a3e GraphicsServices`GSEventRunModal + 161
frame #22: 0x000000011024d8c0 UIKit`UIApplicationMain + 1282
frame #23: 0x000000010e1a928d MemoryGame`main + 109 at AppDelegate.swift:15
frame #24: 0x0000000113fbe145 libdyld.dylib`start + 1
frame #25: 0x0000000113fbe145 libdyld.dylib`start + 1
(lldb)
答案 0 :(得分:0)
您是否在第一个场景中添加了particleEmitter
?您是否使用.targetNode
的{{1}}属性?
如果是这样,我有同样的问题。 SpriteKit中似乎存在一个错误,需要您在更改场景之前手动将particleEmitter
属性设置为.targetNode
。在nil
函数或类似函数中尝试particleEmitter?.targetNode = nil
...
在我的情况下,我使用deinit
只是为了使发射器的粒子出现在背景的顶部,但您可以使用targetNode
和.zPosition
属性获得相同的行为发射器(我将两个属性都设置为高于背景对象.particleZPosition
的数字),从而避免使用.zPosition
。
我希望这会对你有所帮助。