Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory issue (?) when importing into Swift-based project #4

Open
jakintosh opened this issue Oct 12, 2014 · 1 comment
Open

Memory issue (?) when importing into Swift-based project #4

jakintosh opened this issue Oct 12, 2014 · 1 comment

Comments

@jakintosh
Copy link

When importing this code for use in a Swift based SpriteKit (iOS8) project, I would consistently get a crash when trying to run a second animation on top of the queue. After hours of stepping through code, the issue stemmed from assigning _previousAnimation = _currentAnimation in -(void)stopAnimationAndPlayNextInQueue:(BOOL)queueNext which then somehow corrupted the queuedAnimation property.

My solution in the end was to change the property declaration in SGG_Spine.h to read @property (nonatomic, strong) NSString* queuedAnimation. I didn't want to make a pull request because I wasn't 100% sure what the real issue was (or if it would break anything on other target platforms), but I figured I'd leave this here for others to look into, or to save anyone else some time.

The code I was using for those interested:

class GameScene: SKScene {

    var boy: SGG_Spine

    override init(size: CGSize) {
        boy = SGG_Spine.node()
        super.init(size: size)
    }

    required init(coder aDecoder: NSCoder) {
        boy = SGG_Spine.node()
        super.init(coder: aDecoder)
    }

    override func didMoveToView(view: SKView) {
        /* Setup your scene here */
        boy.skeletonFromFileNamed("spineboy", andAtlasNamed: "spineboy", andUseSkinNamed: nil)
        boy.position = CGPointMake(frame.width/2, frame.height/2)
        boy.queuedAnimation = "walk"
        boy.queueIntro = 0.1
        boy.runAnimation("walk", andCount: 0, withIntroPeriodOf: 0.1, andUseQueue: true)
        boy.zPosition = 0
        addChild(boy)
    }

    override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
        /* Called when a touch begins */
        boy.runAnimation("jump", andCount: 0, withIntroPeriodOf: 0.1, andUseQueue: false)
    }

    override func update(currentTime: CFTimeInterval) {
        /* Called before each frame is rendered */
        boy.activateAnimations()
    }
}

When the jump animation completed in touchesBegan() it would crash from trying to access corrupted memory (queuedAnimation).

@mredig
Copy link
Owner

mredig commented Oct 14, 2014

I haven't played with Swift yet, but my initial thought is that there shouldn't be any issues with implementing this change. The only reason I used "assign" was habit formed as I followed tutorials. I looked up what it was actually doing once, but forgot the details. However, I can't forsee there being any issue with making it strong. I'll look into it a bit when I think of it and have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants