سؤال

My app crashes when I run it on my iPhone 4, but it doesn't when I run it on the simulator. I imagine it's something about I'm using more memory than allowed.

I don't have any idea of the error message. The error is just (lldb) and when I tap bt, I get the code below...

I would be very grateful if somebody threw me some light on how to begin understanding this error message, because for me is like Chinese (and of course I'm not Chinese)

(lldb) bt
* thread #1: tid = 0x7396a, 0x37db5ce2 libsystem_platform.dylib`OSSpinLockLock$VARIANT$up + 2, queue = 'com.apple.spritekit.textureOp, stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x37db5ce2 libsystem_platform.dylib`OSSpinLockLock$VARIANT$up + 2
    frame #1: 0x2fa9da68 SpriteKit`SKSpinLockSync(int*, void () block_pointer) + 92
    frame #2: 0x2fa63a48 SpriteKit`-[SKTexture loadImageData] + 300
    frame #3: 0x2fa6735a SpriteKit`-[SKTexture load] + 126
    frame #4: 0x37c79d06 libdispatch.dylib`_dispatch_client_callout + 22
    frame #5: 0x37c8be72 libdispatch.dylib`_dispatch_barrier_sync_f_invoke + 26
    frame #6: 0x2fa672ae SpriteKit`-[SKTexture _loadOnTextureQueue] + 122
    frame #7: 0x2fa98cf0 SpriteKit`SKCSprite::prepareForRendering() const + 1168
    frame #8: 0x2faaaf0c SpriteKit`SKCRenderer::preprocessSpriteImp(std::__1::vector<SKCRenderer::SpriteRenderInfo, std::__1::allocator<SKCRenderer::SpriteRenderInfo> >&, SKRenderQuadPool&, SKCSprite const*, _GLKMatrix4 const&, float, unsigned int&, bool) const + 124
    frame #9: 0x2faab9a4 SpriteKit`SKCRenderer::preprocessSpriteImp(std::__1::vector<SKCRenderer::SpriteRenderInfo, std::__1::allocator<SKCRenderer::SpriteRenderInfo> >&, SKRenderQuadPool&, SKCSprite const*, _GLKMatrix4 const&, float, unsigned int&, bool) const + 2836
    frame #10: 0x2faa73b4 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&) + 52
    frame #11: 0x2faa5e7c SpriteKit`SKCRenderer::preprocessAndSubmitSprite(SKCSprite const*, _GLKMatrix4 const&) + 152
    frame #12: 0x2faa973e SpriteKit`SKCRenderer::submitScene(SKScene*) + 186
    frame #13: 0x2faabf5c SpriteKit`SKCRenderer::renderScene(SKScene*) + 148
    frame #14: 0x2fa71120 SpriteKit`-[SKView _renderContent] + 1072
    frame #15: 0x37c79d06 libdispatch.dylib`_dispatch_client_callout + 22
    frame #16: 0x37c8be72 libdispatch.dylib`_dispatch_barrier_sync_f_invoke + 26
    frame #17: 0x2fa70cc2 SpriteKit`-[SKView renderContent] + 82
    frame #18: 0x2fa6e662 SpriteKit`__29-[SKView setUpRenderCallback]_block_invoke + 130
    frame #19: 0x2fa90dda SpriteKit`-[SKDisplayLink _callbackForNextFrame:] + 254
    frame #20: 0x00216a66 libglInterpose.dylib`-[DYDisplayLinkInterposer forwardDisplayLinkCallback:] + 270
    frame #21: 0x2f8509ce QuartzCore`CA::Display::DisplayLinkItem::dispatch() + 98
    frame #22: 0x2f850778 QuartzCore`CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 344
    frame #23: 0x3243576c IOMobileFramebuffer`IOMobileFramebufferVsyncNotifyFunc + 104
    frame #24: 0x2e0e8a74 IOKit`IODispatchCalloutFromCFMessage + 248
    frame #25: 0x2d3c6e20 CoreFoundation`__CFMachPortPerform + 136
    frame #26: 0x2d3d19de CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 34
    frame #27: 0x2d3d197a CoreFoundation`__CFRunLoopDoSource1 + 346
    frame #28: 0x2d3d014e CoreFoundation`__CFRunLoopRun + 1398
    frame #29: 0x2d33ac26 CoreFoundation`CFRunLoopRunSpecific + 522
    frame #30: 0x2d33aa0a CoreFoundation`CFRunLoopRunInMode + 106
    frame #31: 0x32019282 GraphicsServices`GSEventRunModal + 138
    frame #32: 0x2fbde048 UIKit`UIApplicationMain + 1136
    frame #33: 0x00067b5c superBeeLand`main(argc=1, argv=0x27dbbc64) + 116 at main.m:16
(lldb) 
هل كانت مفيدة؟

المحلول

I have finally found an answer to this. Well, the first clue is that the error is EXC_BAD_ACCESS. That almost always means I'm trying to access memory where there's not an object. Maybe a corrupted pointer, or an object gone away (been deallocated or lost the reference to it).

Going farther down the trace, it appears to be related to texture loading in some way. So I started by looking at any place where I were trying to load/preload textures, create sprites, etc. But it looks like it may be inside the prerender/render loop, which may mean it's not me explicitly loading textures, but Sprite Kit trying to load textures dynamically when needed.

I've tried removing some of the sprites until it doesn't crash, to narrow down which one is giving you the issue and I've finally found it was my hero movement. For his animation, I use a @propertie int _imgNum ; And add it to a [NSString stringWithFormat:@"image%d",_imgNum]; so the _imgNum is the number of the image. I initialize _imgNum at the beginning of the scene and increment it everytime I use it (in didSimulatePhysics() and in touchedMovedWithEvent()). Sometimes the app don't find the image and that's when it crash, but I still don't get why can't load images. I'll better show the code.

        if(_imgNum >= 1 && _imgNum <= 12 )
    {
        [[self childNodeWithName:@"hero"]runAction:[SKAction setTexture:[SKTexture textureWithImageNamed:[NSString stringWithFormat:@"heroRunnning%d",_imgNum]]]];
        _imgNum++;
        if(_imgNum >= 12)
        {
            _imgNum = 1;
        }
    }

نصائح أخرى

I had the problem because I was using this:

SKAction* changeTextTo_Los = [SKAction runBlock:^{
    [myNode removeFromParent];
}];

This caused a crash since he wanted to access the object after running the block or some reason. This was of course not possible because it was removed already.

It seems that [SKAction setTexture:] has a bug. I was getting the same com.apple.spritekit.textureOp bad_access error on the main thread. My app was crashing on older hardware (pre iPad mini) and all of the simulators.

Set the spriteNode's texture instead of using the SKAction on it.

spriteNode.texture = [SKTexture textureWithImageNamed:@"imageName"];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top