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

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?

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.

Hi,

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

Could you try something like this:

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!

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

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)

sorry, missed all the new bits. Updated to:

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

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

No worries!

In our documentation for getPath() (FMOD Engine | Studio API Reference - 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:

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!

1 Like

thanks, that helps indeed. Works great now!

1 Like