# Studio::Bus::getPath() only returns once and corrupts?

**URL:** <https://qa.fmod.com/t/studio-getpath-only-returns-once-and-corrupts/22114>\
**Category:** FMOD Engine\
**Tags:** cpp\
**Created:** [September 22, 2024, 4:26pm UTC](https://qa.fmod.com/t/studio-getpath-only-returns-once-and-corrupts/22114 "2024-09-22T16:26:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mca2](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/mca2/32/3177_2.png) [@mca2](https://qa.fmod.com/u/mca2)\
**Post date:** [September 22, 2024, 4:26pm UTC](https://qa.fmod.com/t/studio-getpath-only-returns-once-and-corrupts/22114/1 "2024-09-22T16:26:54Z")

</div>

I’m trying to get the path of all present buses, but I only get the first bus path.

When I add the code below to simple\_event.cpp in the example folder, `bus_count` gives the correct number of busses, but `getPath()` only returns the first bus path (`bus:/SFX/Character`) but all following are empty. What am I missing here?

```auto
FMOD::Studio::Bus* bus_array{};
int bus_count{};
constexpr int kMaxBusCount{ 64 };
masterBank->getBusList(&bus_array, kMaxBusCount, &bus_count);
for (int i = 0; i < bus_count; ++i) {
    char bus_name{};
    constexpr int kMaxNameSize{ 512 };
    int bus_name_size{};
    bus_array[i].getPath(&bus_name, kMaxNameSize, &bus_name_size);
}

```

And on exit i get the warning `Run-Time Check Failure #2 - Stack around the variable 'bus_name_size' was corrupted.`

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [September 23, 2024, 2:24am UTC](https://qa.fmod.com/t/studio-getpath-only-returns-once-and-corrupts/22114/2 "2024-09-23T02:24:52Z")

</div>

Hi,

The issue may be that you are not initializing the arrays with enough space.

Could you try something like this:

```auto
int busCount = 0;
ERRCHECK(masterBank->getBusCount(&busCount));

FMOD::Studio::Bus** busArr = new FMOD::Studio::Bus * [busCount];
int actualCount = 0;
ERRCHECK(masterBank->getBusList(busArr, busCount, &actualCount));

for (int i = 0; i < busCount; i++)
{
    char* name = new char[256];
    int actual = 0;
    busArr[i]->getPath(name, 256, & actual);
    delete[] name;
}
delete[] busArr;

```

I use a default value of `256` to ensure I retrieve the full name length. I also found your loop was returning a `FMOD error 30 - An invalid object handle was used.` I suggest adding `ERRCHECK` to all FMOD functions to aid debugging.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![mca2](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/mca2/32/3177_2.png) [@mca2](https://qa.fmod.com/u/mca2)\
**Post date:** [September 23, 2024, 7:09am UTC](https://qa.fmod.com/t/studio-getpath-only-returns-once-and-corrupts/22114/3 "2024-09-23T07:09:48Z")

</div>

I reserved 64 buses, that should be enough. Anyway, i added the suggested lines and wrapped all in `ERRCHECK`

```auto
int bus_count{};
ERRCHECK(masterBank->getBusCount(&bus_count));
FMOD::Studio::Bus* bus_array{};
int actual_bus_count{};
ERRCHECK(masterBank->getBusList(&bus_array, bus_count, &actual_bus_count));
for (int i = 0; i < actual_bus_count; ++i) {
    char bus_name{};
    constexpr int kMaxNameSize{ 256 };
    int bus_name_size{};
    ERRCHECK(bus_array[i].getPath(&bus_name, kMaxNameSize, &bus_name_size));
}
delete[] bus_array;

```

`bus_count` and `actual_bus_count` are both 12, so that’s not the issue. The first loop went fine, the second (`i=1`) gave a fatal error:  
`C:\Users\User\source\repos\fmod\examples\simple_event.cpp(78): FMOD error 30 - An invalid object handle was used.`  
with line 78 being the `getPath()` line.

Seems the function internally overflows? Using version `12/7/24 2.02.23 - Studio API minor release (build 144645)`

---

<div class="post-metadata">

**Author:** ![mca2](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/mca2/32/3177_2.png) [@mca2](https://qa.fmod.com/u/mca2)\
**Post date:** [September 23, 2024, 7:18am UTC](https://qa.fmod.com/t/studio-getpath-only-returns-once-and-corrupts/22114/4 "2024-09-23T07:18:08Z")

</div>

sorry, missed all the `new` bits. Updated to:

```auto
int bus_count{};
ERRCHECK(masterBank->getBusCount(&bus_count));
FMOD::Studio::Bus** bus_array = new FMOD::Studio::Bus * [bus_count];
int actual_bus_count{};
ERRCHECK(masterBank->getBusList(bus_array, bus_count, &actual_bus_count));
for (int i = 0; i < actual_bus_count; ++i) {
    char* bus_name = new char[256];
    constexpr int kMaxNameSize{ 256 };
    int bus_name_size{};
    ERRCHECK(bus_array[i]->getPath(bus_name, kMaxNameSize, &bus_name_size));
    delete[] bus_name;
}
delete[] bus_array;

```

That runs fine. Sorry, not used to these old fashioned c-style interfaces. I was expecting `getPath()` would size the ptr as you need to supply the size

```auto
FMOD_RESULT Studio::Bus::getPath(
  char *path,
  int size,
  int *retrieved
);

```

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [September 25, 2024, 12:06am UTC](https://qa.fmod.com/t/studio-getpath-only-returns-once-and-corrupts/22114/5 "2024-09-25T00:06:59Z")

</div>

No worries!

In our documentation for `getPath()` ([FMOD Engine | Studio API Reference - Studio:: Bus::getPath()](https://fmod.com/docs/2.02/api/studio-api-bus.html#studio_bus_getpath)) it notes that the `path` and the `retrieve` parameters are optional. This allows you to use the get path function to retrieve the total length of the name using something like this:

```auto
for (int i = 0; i < busCount; i++)
{
    int actual = 0;
    ERRCHECK(busArr[i]->getPath(nullptr, 0, &actual));
    char* name = new char[actual];
    ERRCHECK(busArr[i]->getPath(name, actual, 0));
    delete[] name;
}

```

I use the first call of `getPath()` to retrieve the number of characters in the name, and then I retrieve the actual name in the second call.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![mca2](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/mca2/32/3177_2.png) [@mca2](https://qa.fmod.com/u/mca2)\
**Post date:** [September 25, 2024, 10:24pm UTC](https://qa.fmod.com/t/studio-getpath-only-returns-once-and-corrupts/22114/6 "2024-09-25T22:24:40Z")

</div>

thanks, that helps indeed. Works great now!
