# DropCharge SKAudioNode crash page 444

**URL:** <https://forums.kodeco.com/t/dropcharge-skaudionode-crash-page-444/11295>\
**Category:** 2D iOS & tvOS Games by Tutorials\
**Created:** [March 28, 2016, 11:53am UTC](https://forums.kodeco.com/t/dropcharge-skaudionode-crash-page-444/11295 "2016-03-28T11:53:28Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![senioriceman](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/senioriceman/32/52208_2.png) [@senioriceman](https://forums.kodeco.com/u/senioriceman)\
**Post date:** [March 28, 2016, 11:53am UTC](https://forums.kodeco.com/t/dropcharge-skaudionode-crash-page-444/11295/1 "2016-03-28T11:53:28Z")

</div>

In the book’s 444th page the code is crashing. I followed the code with break point and the variable backgroundMusic is always nil. Maybe this crash is happening after new update of Xcode. I tried to run the final template of the chapter 17 and it also crashing in the same line

func playBackgroundMusic(name: String) {  
var delay = 0.0  
if backgroundMusic != nil {  
backgroundMusic.removeFromParent()  
} else {  
delay = 0.1 }  
runAction(SKAction.waitForDuration(delay)) {  
self.backgroundMusic = SKAudioNode(fileNamed: name)  
self.backgroundMusic.autoplayLooped = true//Crashing line  
self.addChild(self.backgroundMusic)  
} }

Error is:(backgroundMusic is nil cannot find the file)  
fatal error: unexpectedly found nil while unwrapping an Optional value  
(lldb)

Can anyone find the reason please. Also yes I have the sounds file in the directory

---

<div class="post-metadata">

**Author:** ![stoneburner](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/stoneburner/32/75106_2.png) [@stoneburner](https://forums.kodeco.com/u/stoneburner)\
**Post date:** [March 28, 2016, 4:23pm UTC](https://forums.kodeco.com/t/dropcharge-skaudionode-crash-page-444/11295/2 "2016-03-28T16:23:07Z")

</div>

I see the same here, it worked fine before the latest XCode update, and it will also work again if i remove the background music

---

<div class="post-metadata">

**Author:** ![hula-smula](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/hula-smula/32/55213_2.png) [@hula-smula](https://forums.kodeco.com/u/hula-smula)\
**Post date:** [March 28, 2016, 6:11pm UTC](https://forums.kodeco.com/t/dropcharge-skaudionode-crash-page-444/11295/3 "2016-03-28T18:11:22Z")

</div>

The reason is that in Xcode 7.3 the code statement that says:

runAction(SKAction.waitForDuration(delay)) {

is not supported and needs to be reinitialized before using it .  
so it is easier to just change the func play background Music to  
the following.

func playBackgroundMusic(name: String) {

```
    if backgroundMusic != nil {
        backgroundMusic.removeFromParent()
        if bgMusicAlarm != nil {
            bgMusicAlarm.removeFromParent()
        } else {
            bgMusicAlarm = SKAudioNode(fileNamed: "alarm.wav")
            bgMusicAlarm.autoplayLooped = true
            addChild(bgMusicAlarm)
        }
    }
    runAction(SKAction.playSoundFileNamed("SpaceGame.caf", waitForCompletion: false))
    self.backgroundMusic = SKAudioNode(fileNamed: name)
    }

```

and then put in this statement :  
var backgroundMusic: SKAudioNode!

under properties right above the line:  
var bgMusicAlarm: SKAudioNode!

and drop charge should work exactly as before in Xcode version 7.2

---

<div class="post-metadata">

**Author:** ![senioriceman](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/senioriceman/32/52208_2.png) [@senioriceman](https://forums.kodeco.com/u/senioriceman)\
**Post date:** [March 28, 2016, 8:48pm UTC](https://forums.kodeco.com/t/dropcharge-skaudionode-crash-page-444/11295/4 "2016-03-28T20:48:03Z")

</div>

Thanks for your comment but still not working. As I followed the code with debugging breakpoint the backgroundMusic variable is still nil. The code is not giving any error but there is no music playing either. Also shouldn’t we need to add backgroundMusic as child to scene but since it is nil this will give error of course. I hope ray and their team releases an update. Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![hula-smula](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/hula-smula/32/55213_2.png) [@hula-smula](https://forums.kodeco.com/u/hula-smula)\
**Post date:** [March 28, 2016, 9:32pm UTC](https://forums.kodeco.com/t/dropcharge-skaudionode-crash-page-444/11295/5 "2016-03-28T21:32:01Z")

</div>

yes, in the code I sent two lines were missing:  
they go right after self.background = SKAudioNode(fileNamed: name)

func playBackgroundMusic(name: String) {

```
    if backgroundMusic != nil {
        backgroundMusic.removeFromParent()
        if bgMusicAlarm != nil {
            bgMusicAlarm.removeFromParent()
        } else {
            bgMusicAlarm = SKAudioNode(fileNamed: "alarm.wav")
            bgMusicAlarm.autoplayLooped = true
            addChild(bgMusicAlarm)
        }
    }
    runAction(SKAction.playSoundFileNamed("SpaceGame.caf", waitForCompletion: false))
    self.backgroundMusic = SKAudioNode(fileNamed: name)
    self.backgroundMusic.autoplayLooped = true
    self.addChild(self.backgroundMusic)

```

}

---

<div class="post-metadata">

**Author:** ![keydogg](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/keydogg/32/102075_2.png) [@keydogg](https://forums.kodeco.com/u/keydogg)\
**Post date:** [March 28, 2016, 11:36pm UTC](https://forums.kodeco.com/t/dropcharge-skaudionode-crash-page-444/11295/6 "2016-03-28T23:36:30Z")

</div>

This crashes for me as well, even with hula-semula’s latest suggestion.

I also tried to to clean the product, Xcode \> Product \> Clean, and also deleted all the Xcode derived data from ~/Library/Developer/Xcode/DerivedData

Looks like something else is going on with this, if multiple people are crashing the same way. Maybe an Xcode or SDK update issue??

All the same code works fine if I run with Xcode 7.2.1. You can download that version again from here:

> **[Sign In - Apple](https://idmsa.apple.com/IDMSWebAuth/signin.html?path=%2Fdownload%2Fall%2F&appIdKey=891bd3417a7776362562d2197f89480a8547b108fd934911bcbea0110d07f757&rv=0)**
>
> Sign in with your Apple ID

---

<div class="post-metadata">

**Author:** ![hula-smula](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/hula-smula/32/55213_2.png) [@hula-smula](https://forums.kodeco.com/u/hula-smula)\
**Post date:** [March 29, 2016, 12:41am UTC](https://forums.kodeco.com/t/dropcharge-skaudionode-crash-page-444/11295/7 "2016-03-29T00:41:27Z")

</div>

actually We don’t need to add child or insert those two additional lines as I don’t have them in my code and it plays the background music perfect so maybe there is another issue at hand,if you like I will send you a complete copy of my game scene . swift file for you to compare with yours

---

<div class="post-metadata">

**Author:** ![senioriceman](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/senioriceman/32/52208_2.png) [@senioriceman](https://forums.kodeco.com/u/senioriceman)\
**Post date:** [March 29, 2016, 11:27am UTC](https://forums.kodeco.com/t/dropcharge-skaudionode-crash-page-444/11295/8 "2016-03-29T11:27:45Z")

</div>

Thanks for all comments fellas. Lets wait for a while and see if new updates will fix because it seems 7.3 update is the reason

---

<div class="post-metadata">

**Author:** ![senioriceman](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/senioriceman/32/52208_2.png) [@senioriceman](https://forums.kodeco.com/u/senioriceman)\
**Post date:** [March 30, 2016, 8:58pm UTC](https://forums.kodeco.com/t/dropcharge-skaudionode-crash-page-444/11295/9 "2016-03-30T20:58:36Z")

</div>

DropCharge Background crash solution for xcode 7.3 is:

Firstly to add sounds file properly create a group named sounds and right click on it then click “Add files to” then select sound files .caf .wav etc. from resources. When directly dragging the resources to the environment it did not see the files as it shows the folder with not yellow but blue icon.

Secondly FOR CODİNG PART in the properties creat background music directly by typing

var backgroundMusic = SKAudioNode(fileNamed: “SpaceGame.caf”)

then change the function as

func playBackgroundMusic(){  
self.backgroundMusic.autoplayLooped = true  
self.addChild(backgroundMusic)  
}

Call function in the didMoveToView

If you creat the backgroundMusic in the function instead of properties it crashes.

---

<div class="post-metadata">

**Author:** ![iacredot3](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/iacredot3/32/110937_2.png) [@iacredot3](https://forums.kodeco.com/u/iacredot3)\
**Post date:** [April 3, 2016, 9:34pm UTC](https://forums.kodeco.com/t/dropcharge-skaudionode-crash-page-444/11295/10 "2016-04-03T21:34:34Z")

</div>

This temporarily gets me past the issue on page 444, but as you progress through it doesn’t fix the issue because you renamed the method so the other examples that send a file name parameter to that method needs to be addressed too.

---

<div class="post-metadata">

**Author:** ![glorysaber](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/glorysaber/32/100910_2.png) [@glorysaber](https://forums.kodeco.com/u/glorysaber)\
**Post date:** [April 5, 2016, 8:09pm UTC](https://forums.kodeco.com/t/dropcharge-skaudionode-crash-page-444/11295/11 "2016-04-05T20:09:48Z")

</div>

> [@senioriceman](#):
>
> SKAudioNode(fileNamed: “SpaceGame.caf”)

Im Still Having this issue too but I fixed it by changing the method to this:

func playBackgroundMusic(name: String) {  
if self.backgroundMusic != nil {  
self.backgroundMusic.removeFromParent()  
}  
let backgroundMusic = SKAudioNode(fileNamed: name)  
backgroundMusic.autoplayLooped = true  
self.backgroundMusic = backgroundMusic  
addChild(backgroundMusic)  
}

This keeps the method working as before and the name is the same.

---

<div class="post-metadata">

**Author:** ![senioriceman](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/senioriceman/32/52208_2.png) [@senioriceman](https://forums.kodeco.com/u/senioriceman)\
**Post date:** [April 5, 2016, 8:26pm UTC](https://forums.kodeco.com/t/dropcharge-skaudionode-crash-page-444/11295/12 "2016-04-05T20:26:43Z")

</div>

Yes this works either

---

<div class="post-metadata">

**Author:** ![kevcol](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/kevcol/32/75040_2.png) [@kevcol](https://forums.kodeco.com/u/kevcol)\
**Post date:** [April 8, 2016, 5:30pm UTC](https://forums.kodeco.com/t/dropcharge-skaudionode-crash-page-444/11295/13 "2016-04-08T17:30:19Z")

</div>

Works for me as well. But has anyone gotten the alarm sound back in, as well?

This errors (nil found) for me if I uncomment the bgMusicAlarm code:

func playBackgroundMusic(name: String) {

```
    if self.backgroundMusic != nil {
        self.backgroundMusic.removeFromParent()
    
         /* if bgMusicAlarm != nil {
                bgMusicAlarm.removeFromParent()
            } else {
                bgMusicAlarm = SKAudioNode(fileNamed: "alarm.wav")
                bgMusicAlarm.autoplayLooped = true
                addChild(bgMusicAlarm)
            } */
    
    }
    
    let backgroundMusic = SKAudioNode(fileNamed: name)
    backgroundMusic.autoplayLooped = true
    self.backgroundMusic = backgroundMusic
    addChild(backgroundMusic)
}

```

---

<div class="post-metadata">

**Author:** ![senioriceman](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/senioriceman/32/52208_2.png) [@senioriceman](https://forums.kodeco.com/u/senioriceman)\
**Post date:** [April 8, 2016, 6:00pm UTC](https://forums.kodeco.com/t/dropcharge-skaudionode-crash-page-444/11295/14 "2016-04-08T18:00:24Z")

</div>

```
func playBackgroundMusic(name:String){
    if backgroundMusic != nil {
        backgroundMusic.removeFromParent()
        if bgMusicAlarm != nil {
            bgMusicAlarm.removeFromParent()
        }
        else {
            let temp = SKAudioNode(fileNamed: "alarm.wav")
            temp.autoplayLooped = true
            bgMusicAlarm = temp
            addChild(bgMusicAlarm)
        }
    }
    let temp = SKAudioNode(fileNamed: name)
    temp.autoplayLooped = true
    backgroundMusic = temp
    addChild(backgroundMusic)
}

```

---

<div class="post-metadata">

**Author:** ![kevcol](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/kevcol/32/75040_2.png) [@kevcol](https://forums.kodeco.com/u/kevcol)\
**Post date:** [April 8, 2016, 6:07pm UTC](https://forums.kodeco.com/t/dropcharge-skaudionode-crash-page-444/11295/15 "2016-04-08T18:07:32Z")

</div>

Excellent! That works. Thanks much

---

<div class="post-metadata">

**Author:** ![senioriceman](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/senioriceman/32/52208_2.png) [@senioriceman](https://forums.kodeco.com/u/senioriceman)\
**Post date:** [April 8, 2016, 6:32pm UTC](https://forums.kodeco.com/t/dropcharge-skaudionode-crash-page-444/11295/16 "2016-04-08T18:32:48Z")

</div>

No problem bruv 😁

---

<div class="post-metadata">

**Author:** ![thebelg](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/thebelg/32/105896_2.png) [@thebelg](https://forums.kodeco.com/u/thebelg)\
**Post date:** [April 26, 2016, 2:38pm UTC](https://forums.kodeco.com/t/dropcharge-skaudionode-crash-page-444/11295/17 "2016-04-26T14:38:51Z")

</div>

Thanks for this “workaround”.
