应用程序因 EXC_BAD_ACCESS 崩溃(代码 = 1,地址 = 0x0)

Posted

技术标签:

【中文标题】应用程序因 EXC_BAD_ACCESS 崩溃(代码 = 1,地址 = 0x0)【英文标题】:App crash with EXC_BAD_ACCESS (code = 1, address = 0x0) 【发布时间】:2015-09-29 16:43:19 【问题描述】:

我知道有很多这样的问题,所以我尽量提供尽可能多的细节。我用 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) 

【问题讨论】:

您是否尝试过使用地址清理程序? @Dudi 我用地址消毒剂跟踪更新了我的问题。 【参考方案1】:

您是否在第一个场景中添加了particleEmitter?你是否使用了particleEmitter.targetNode 属性?

如果是这样,我也遇到了同样的问题。 SpriteKit 中似乎存在一个错误,需要您在更改场景之前手动将 .targetNode 属性设置为 nil。在 deinit 函数或类似函数中尝试 particleEmitter?.targetNode = nil...

在我的例子中,我使用targetNode 只是为了使发射器的粒子出现在背景之上,但是您可以使用发射器的.zPosition.particleZPosition 属性获得相同的行为(我设置这两个属性的数字都高于背景对象的.zPosition),从而避免使用targetNode

希望对你有帮助。

【讨论】:

不,我的任何场景都不使用发射器。 那我帮不了你了,对不起。我不擅长阅读bt 输出。 :(

以上是关于应用程序因 EXC_BAD_ACCESS 崩溃(代码 = 1,地址 = 0x0)的主要内容,如果未能解决你的问题,请参考以下文章

应用程序因 AVAudioSession privateBeginInterruption 而崩溃

xamarin ios 应用程序因 CBCentralManager 崩溃

委托分配导致 EXC_BAD_ACCESS

QT 应用程序中的 exc_bad_access 崩溃

开始运行应用程序时 EXC_BAD_ACCESS 崩溃?

NSLayoutConstraint VFL 因为 EXC_BAD_ACCESS 而崩溃