SpriteKit: EXC_BAD_ACCESS SpriteKit`SKCShapeSprite::getAccumulatedBounds() crash

不问归期 提交于 2019-12-13 05:04:50

问题


After upgrading to iOS8, SpriteKit game crashes with EXC_BAD_ACCESS. It happens for no apparent reason, after playing a bit, at random time. No info from Exception breakpoint and NSZombie detection, so no way to detect the line in the code that causes the error. Checked both on a simulator and a device.

The backtrace:

* thread #1: tid = 0x13fa2, 0x2b3977f0 SpriteKit`SKCShapeSprite::getAccumulatedBounds() const + 84, queue = 'com.apple.spritekit.renderQueue', stop reason = EXC_BAD_ACCESS (code=1, address=0x11)
frame #0: 0x2b3977f0 SpriteKit`SKCShapeSprite::getAccumulatedBounds() const + 84
frame #1: 0x2b3e3086 SpriteKit`SKCRenderer::preprocessSpriteImp(std::__1::vector<SKCRenderer::SpriteRenderInfo, std::__1::allocator<SKCRenderer::SpriteRenderInfo> >&, SKRenderQuadPool&, SKCSprite const*, _GLKMatrix4 const&, float, unsigned int&, bool) + 1030
frame #2: 0x2b3e39b4 SpriteKit`SKCRenderer::preprocessSpriteImp(std::__1::vector<SKCRenderer::SpriteRenderInfo, std::__1::allocator<SKCRenderer::SpriteRenderInfo> >&, SKRenderQuadPool&, SKCSprite const*, _GLKMatrix4 const&, float, unsigned int&, bool) + 3380
frame #3: 0x2b3ddbe2 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&) + 94
frame #4: 0x2b3e29be SpriteKit`SKCRenderer::preprocessAndSubmitSprite(SKCSprite const*, _GLKMatrix4 const&) + 154
frame #5: 0x2b3e0b32 SpriteKit`SKCRenderer::submitScene(SKScene*, bool) + 530
frame #6: 0x2b3e4b98 SpriteKit`SKCRenderer::renderScene(SKScene*, bool) + 152
frame #7: 0x2b37bf4a SpriteKit`-[SKView _renderContent] + 1098
frame #8: 0x00683abe libdispatch.dylib`_dispatch_client_callout + 22
frame #9: 0x0068b270 libdispatch.dylib`_dispatch_barrier_sync_f_invoke + 96
frame #10: 0x2b37bad2 SpriteKit`-[SKView renderContent] + 82
frame #11: 0x2b37885c SpriteKit`__29-[SKView setUpRenderCallback]_block_invoke + 116
frame #12: 0x2b3a9fcc SpriteKit`-[SKDisplayLink _callbackForNextFrame:] + 248
frame #13: 0x005e61b6 libglInterpose.dylib`-[DYDisplayLinkInterposer forwardDisplayLinkCallback:] + 270
frame #14: 0x2af4ed7a QuartzCore`CA::Display::DisplayLinkItem::dispatch() + 98
frame #15: 0x2af4ebe2 QuartzCore`CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 366
frame #16: 0x2f7fe82e IOMobileFramebuffer`IOMobileFramebufferVsyncNotifyFunc + 90
frame #17: 0x28f7e51c IOKit`IODispatchCalloutFromCFMessage + 256
frame #18: 0x28010be4 CoreFoundation`__CFMachPortPerform + 132
frame #19: 0x28021022 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 34
frame #20: 0x28020fbe CoreFoundation`__CFRunLoopDoSource1 + 346
frame #21: 0x2801f5e0 CoreFoundation`__CFRunLoopRun + 1608
frame #22: 0x27f6cdb0 CoreFoundation`CFRunLoopRunSpecific + 476
frame #23: 0x27f6cbc2 CoreFoundation`CFRunLoopRunInMode + 106
frame #24: 0x2f2f8050 GraphicsServices`GSEventRunModal + 136
frame #25: 0x2b538a30 UIKit`UIApplicationMain + 1440
* frame #26: 0x000b4f2c p01g01`main(argc=1, argv=0x00418a84) + 116 at main.m:16

This error appeared only after I solved removeFromParent issue that caused SpriteKit'SKCSprite::update(double). Head here for the reference: EXC_BAD_ACCESS after upgrading to iOS8 SpriteKit game

Any suggestions will be appreciated!


回答1:


Try this by setting a unique name for the name property. Somehow worked for me.

static NSInteger count = 0;

@interface Power ()

- (instancetype)init
{
    if (self = [super init]) {
        count++;
        self.name = @(count).stringValue;
    } return self
}

@end

Notice the objects were deallocating more than once. Maybe because wasn't able to distinguish one object to another of the same type.



来源:https://stackoverflow.com/questions/26136963/spritekit-exc-bad-access-spritekitskcshapespritegetaccumulatedbounds-crash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!