# ERR\_INVALID\_HANDLE, seemingly randomly on getSoundSize(out soundSize);

**URL:** https://qa.fmod.com/t/err-invalid-handle-seemingly-randomly-on-getsoundsize-out-soundsize/19563
**Category:** Unity
**Created:** [November 22, 2022, 4:59pm UTC](https://qa.fmod.com/t/err-invalid-handle-seemingly-randomly-on-getsoundsize-out-soundsize/19563 "2022-11-22T16:59:43Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![eddyster](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@eddyster](https://qa.fmod.com/u/eddyster)
#### Post date: [November 22, 2022, 4:59pm UTC](https://qa.fmod.com/t/err-invalid-handle-seemingly-randomly-on-getsoundsize-out-soundsize/19563/1 "2022-11-22T16:59:43Z")

</div>

Hi guys, hoping for some help on this one. I’ve looked about the forum and through the documentation thoroughly but can’t find anything that might explain this one.

The basic problem is that when trying to getSoundSize of an EventInstance programmatically at runtime, FMOD will return an OK result with the correct value for sound size for some events, but for other events it returns 0 with the error code ERR\_INVALID\_HANDLE. I can’t figure out what constitutes a valid handle, as almost all of the data / playback information related to the two events is identical.

Needless to say, both events have a sound size setting (both set to user, and value 1.0 if you’re interested).

The affected instances are failing the ‘isValid’ check, but I can’t get any decent error information to find out why exactly it is failing. I want to run this code once, not every frame, so am trying to figure this error out.

The error is persistent and repeatable for the affected events, and other events can get the sound size value with no such error. It isn’t random.

Any ideas as to why some of my events will have an ‘invalid handle’?

Many thanks all

---

<div class="post-metadata">

### Author: ![Leah\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/leah_fmod/32/3685_2.png) [@Leah\_FMOD](https://qa.fmod.com/u/Leah_FMOD)
#### Post date: [November 27, 2022, 11:39pm UTC](https://qa.fmod.com/t/err-invalid-handle-seemingly-randomly-on-getsoundsize-out-soundsize/19563/2 "2022-11-27T23:39:08Z")

</div>

Hi,

`ERR_INVALID_HANDLE` is an error code that indicates that the underlying object has been destroyed. Since you’re working with `EventInstance` and `EventDescription`, it’s likely that you’ve done something that has caused a given `EventInstance` or `EventDescription` to be destroyed before calling `Studio.EventDescription.getSoundSize()`.

It’s impossible to diagnose what the issue specifically is without seeing your code, but a common cause of this would be calling `Studio.EventInstance.release()` on an instance, thereby flagging it for destruction when playback stops, and then after playback has stopped calling `Studio.EventInstance.getSoundSize()` on the destroyed instance.

---

<div class="post-metadata">

### Author: ![eddyster](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@eddyster](https://qa.fmod.com/u/eddyster)
#### Post date: [December 5, 2022, 11:46am UTC](https://qa.fmod.com/t/err-invalid-handle-seemingly-randomly-on-getsoundsize-out-soundsize/19563/3 "2022-12-05T11:46:22Z")

</div>

Thanks Leah. I haven’t called .release or destroyed the object, but you might have pointed me in the right direction anyway. The sounds aren’t virtual, and aren’t in audible range when calling the function. Could that be it? About to test that theory now.

---

<div class="post-metadata">

### Author: ![eddyster](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@eddyster](https://qa.fmod.com/u/eddyster)
#### Post date: [December 5, 2022, 12:09pm UTC](https://qa.fmod.com/t/err-invalid-handle-seemingly-randomly-on-getsoundsize-out-soundsize/19563/4 "2022-12-05T12:09:06Z")

</div>

I think some scene optimization was to blame (keeping assets unloaded even after initialization)

This little loop called in Update has fixed it

```
    // check if sound is valid before attempting to get soundsize
    if (EventInstance.isValid() && SoundSizeSet == false)
    {
        ed.getSoundSize(out SoundSize);
        SoundSizeSet = true;
        FMOD.RESULT result = EventInstance.getDescription(out ed);
     }

```
