Search code examples
iossprite-kitskscene

SKScene crashing the app while closing the view controller


I am following tutorial to float hearts like Periscope.

Link to Tutorial

To give basic hint, I am posting the code below

let heartHeight: CGFloat = 18.0

let heartsFile = "heart-bubbles.sks"

class HeartBubblesScene : SKScene {
var emitter: SKEmitterNode?

override func didMoveToView(view: SKView) {
    scaleMode = .ResizeFill // make scene's size == view's size
    //backgroundColor = UIColor.clearColor()
}

func beginBubbling() {

    emitter = SKEmitterNode(fileNamed: heartsFile)

    let x = floor(size.width / 2.0)
    let y = heartHeight

    emitter!.position = CGPointMake(x, y)

    emitter!.name = "heart-bubbles"
    emitter!.targetNode = self

    emitter?.numParticlesToEmit = 1

    addChild(emitter!)

    emitter?.resetSimulation()
}

In my viewdidload, I have code like this to present the scene

    heartBubblesView.presentScene(heartBubblesScene)

Where heartBubblesView is a SKView, which I made through an Outlet.

The issue arises when I to and fro to that view controller; suddenly, it crashed and shows me below logical:

SpriteKit`std::__1::__tree_iterator*, int> std::__1::__tree, std::__1::allocator >::find: 0x29fd0f4c <+0>: ldr r3, [r0, #4]! 0x29fd0f50 <+4>: cbz r3, 0x29fd0f82 ; <+54> 0x29fd0f52 <+6>: ldr.w r12, [r1] 0x29fd0f56 <+10>: mov r9, r0 -> 0x29fd0f58 <+12>: ldr r2, [r3, #0x10] 0x29fd0f5a <+14>: cmp r2, r12 0x29fd0f5c <+16>: bhs 0x29fd0f66 ; <+26> 0x29fd0f5e <+18>: ldr r3, [r3, #0x4] 0x29fd0f60 <+20>: cmp r3, #0x0 0x29fd0f62 <+22>: bne 0x29fd0f58 ; <+12> 0x29fd0f64 <+24>: b 0x29fd0f70 ; <+36> 0x29fd0f66 <+26>: ldr r2, [r3] 0x29fd0f68 <+28>: mov r9, r3 0x29fd0f6a <+30>: cmp r2, #0x0 0x29fd0f6c <+32>: mov r3, r2 0x29fd0f6e <+34>: bne 0x29fd0f58 ; <+12> 0x29fd0f70 <+36>: cmp r9, r0 0x29fd0f72 <+38>: beq 0x29fd0f82 ; <+54> 0x29fd0f74 <+40>: ldr.w r2, [r9, #0x10] 0x29fd0f78 <+44>: ldr r1, [r1] 0x29fd0f7a <+46>: cmp r1, r2 0x29fd0f7c <+48>: it lo 0x29fd0f7e <+50>: movlo r9, r0 0x29fd0f80 <+52>: b 0x29fd0f84 ; <+56> 0x29fd0f82 <+54>: mov r9, r0 0x29fd0f84 <+56>: mov r0, r9 0x29fd0f86 <+58>: bx lr

Then I tried to add the deinit to above class

deinit
{
    emitter?.targetNode = nil
    emitter!.removeAllChildren()

}

That does not work either.


Solution

  • I don't know but I put this below deinitialser method in my view controller with removing all children of that SKScene seems to resolve the issue.

      deinit
    {
       heartBubblesScene.removeAllChildren()
    }