# FMOD ChannelHandle returns null in Release, but not Debug

**URL:** <https://qa.fmod.com/t/fmod-channelhandle-returns-null-in-release-but-not-debug/18450>\
**Category:** FMOD Engine\
**Tags:** cpp\
**Created:** [February 28, 2022, 2:57pm UTC](https://qa.fmod.com/t/fmod-channelhandle-returns-null-in-release-but-not-debug/18450 "2022-02-28T14:57:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![farewind](https://avatars.discourse-cdn.com/v4/letter/f/82dd89/32.png) [@farewind](https://qa.fmod.com/u/farewind)\
**Post date:** [February 28, 2022, 2:57pm UTC](https://qa.fmod.com/t/fmod-channelhandle-returns-null-in-release-but-not-debug/18450/1 "2022-02-28T14:57:59Z")

</div>

Debug:  
 ![fmod error working 1](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/3/3e7b532bc67b42484fc110d7b1d42ec3abe5354f.png)

 ![fmod error working 2](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/c/c39a806ab4a972c8ebdd0ad838747e7d6cea10be.png)  
Release:  
 ![fmod error null 1](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/a/a086950a49a8c92d6db0547854562824c4a8edab.png)  
 ![fmod error null 2](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/0/0d66dcc8430ae414b1ec92c921996c6d3d8c25bf.png)

Greetings.

I’ve been making use of my own AudioEngine in c++, visualstudio for a group game project, and have ran into a strange issue regarding PlaySound.

As the images above show, creating a channel inside of my own “Play 3D Sound” Function has thus far been working flawlessly in Debug mode, the sound plays in the correct position, etc etc.

However as soon as we started switching to Release, the function now suddenly returns NULL on the channel handle, rather than…whatever 0xcccccccc is. Normally I create a temporary channel, define it with playsound and then set its position in the world to play properly, but in Release, it returning null results in it never being set Post play-sound, and results in a crash.

I have no clue what caused the change between the two modes, if its some internal FMOD setting I have to set at system::init, or if its completely separate from FMOD entirely, somehow.

I’d appreciate any and all answers and hypothesis regarding this.

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [March 7, 2022, 12:58am UTC](https://qa.fmod.com/t/fmod-channelhandle-returns-null-in-release-but-not-debug/18450/2 "2022-03-07T00:58:58Z")

</div>

What version of FMOD are you using, and are the examples running fine in Release and Debug mode?  
I think some logging might give a better idea of what’s going wrong. You can set this up by swapping out your libs for the “fmodL” logging libs, and calling `FMOD::Debug_Initialize(FMOD_DEBUG_LEVEL_LOG)` at the start of your application. This should give you some more useful ingormation in your console about any internal failures. Other than that, is `playSound` returning `FMOD_OK`?

---

<div class="post-metadata">

**Author:** ![farewind](https://avatars.discourse-cdn.com/v4/letter/f/82dd89/32.png) [@farewind](https://qa.fmod.com/u/farewind)\
**Post date:** [March 10, 2022, 9:06am UTC](https://qa.fmod.com/t/fmod-channelhandle-returns-null-in-release-but-not-debug/18450/3 "2022-03-10T09:06:13Z")

</div>

Thanks for the response!

Regarding the version, I believe I’m using FMOD Core 2.0, atleast that’s the version name mentioned in the main fmod.h file.

![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/8/8804723844e9760346ce2ceeb4b82604cb8949f4.png)

I’ve yet to try your suggested Debug method, but I am curious what Release exactly constitutes. I’ve simply initialized things as normal, following one of the guides featured on the website for fmod core. Is that the same as Release?

Playsound returns FMOD\_OK correctly in visual studio’s debug.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/e/ea76588767cc0fc825d18df3044ed0030a539600.png)

However in its Release mode, since aTempChannel becomes null and remains as null, it returns an error-handle.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/e/e548e17ab50e6a44fa4d2e9f4c7cc683a3c75d8f.jpeg)

Here’s an image of my entire function, which uses Playsound.  
There’s some things related to position and such which can be ignored, the main issue is tied to FMOD::Channel\* aTempChannel, and the playSound call below it.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/6/6f3283a2bc8d7aeb78df73e44dd28c267ee4577a.png)

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [March 11, 2022, 3:53am UTC](https://qa.fmod.com/t/fmod-channelhandle-returns-null-in-release-but-not-debug/18450/4 "2022-03-11T03:53:34Z")

</div>

> [@farewind](#):
>
> Regarding the version, I believe I’m using FMOD Core 2.0

You can get the version by checking the hex value of the [`FMOD_VERSION`](https://fmod.com/resources/documentation-api?version=2.02&page=core-api-common.html#fmod_version) preprocessor directive, it should be something like 0x00020203 for FMOD 2.02.03.

> [@farewind](#):
>
> However in its Release mode, since aTempChannel becomes null and remains as null, it returns an error-handle.

That result indicates that one of your parameters was invalid, most likely there’s a bad value in that array. So things to check would be:

- What values are in the `myNEWSounds` array
- What is the value of `aSound`
- Is the value of `aSound` less than the length of the array
- What is the value of `myNEWSounds` at index `aSound`.

---

<div class="post-metadata">

**Author:** ![farewind](https://avatars.discourse-cdn.com/v4/letter/f/82dd89/32.png) [@farewind](https://qa.fmod.com/u/farewind)\
**Post date:** [March 11, 2022, 9:02am UTC](https://qa.fmod.com/t/fmod-channelhandle-returns-null-in-release-but-not-debug/18450/5 "2022-03-11T09:02:22Z")

</div>

> [@jeff\_fmod](#):
>
> You can get the version by checking the hex value of the [`FMOD_VERSION`](https://fmod.com/resources/documentation-api?version=2.02&page=core-api-common.html#fmod_version) preprocessor directive, it should be something like 0x00020203 for FMOD 2.02.03.

Ah! Thank you. According to the value I saw, I appear to be using the same version as the one you gave as an example. FMOD 2.02.03.

> [@jeff\_fmod](#):
>
> - What values are in the `myNEWSounds` array
> - What is the value of `aSound`
> - Is the value of `aSound` less than the length of the array
> - What is the value of `myNEWSounds` at index `aSound` .

Since my last post, I’ve realized that not only does this playsound not work, but everything just seems to have broken completely in Release mode. My entire NEWSounds array, and all of its assigned sounds are NULL.  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/b/bf34063ae9f4f84ab9c070e3d983fc5534c35484.png)  
Despite things still working flawlessly in Debug.  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/0/071ccb17eacc2ef90f2bc8208046fdd5d5564192.jpeg)  
The values themselves are correct though. aSound’s assigned value is 19, which is the sound I called for. And the size of NewSounds is 23, which is also correct to the amount of sounds loaded. The value of aSound also doesnt exceed the length of the array or anything like that.

At this point my worry is that something in the way things are handled on startup have somehow depending on if its in Debug or Release, but from my digging around, nothing regarding my audioengine or anything else tied to it seems to have any restrictions depending on mode, or something like that.

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [March 16, 2022, 1:11am UTC](https://qa.fmod.com/t/fmod-channelhandle-returns-null-in-release-but-not-debug/18450/6 "2022-03-16T01:11:07Z")

</div>

That narrows it down a bit more and explains the crash. How/where are you populating this array of sounds?

---

<div class="post-metadata">

**Author:** ![farewind](https://avatars.discourse-cdn.com/v4/letter/f/82dd89/32.png) [@farewind](https://qa.fmod.com/u/farewind)\
**Post date:** [March 17, 2022, 10:16am UTC](https://qa.fmod.com/t/fmod-channelhandle-returns-null-in-release-but-not-debug/18450/7 "2022-03-17T10:16:31Z")

</div>

I managed to solve it! And of course the issue was way simpler than I had thought.

In my LoadSounds function, there was indeed a “ifdef debug” line present, I had just assumed that it wasn’t affecting anything, since it never caused a crash there.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/b/bd74336abd97992cddf8d9c83365cc291e009261.png)

In hindsight I can’t believe I actually missed it, it’s right there in plain sight.

Regardless, thank you for the assistance, Jeff. You helped me narrow down what exactly the cause was, since originally I thought the issue was happening way deeper into the code than it actually was.

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [March 17, 2022, 10:56pm UTC](https://qa.fmod.com/t/fmod-channelhandle-returns-null-in-release-but-not-debug/18450/8 "2022-03-17T22:56:53Z")

</div>

Ahh that would be an easy one to miss actually. Glad you got to the bottom of it!
