Clarification for "array of memory allocated by the user"

In updating to a new version, we have a question. For functions that require an “array of memory allocated by the user”, it’s unclear to us what that actually means. Does that mean 1) an array of classes?, or 2) an array of class pointers?

This is one such function:

FMOD_RESULT Studio::Bank::getEventList(
  Studio::EventDescription **array,
  int capacity,
  int *count
);

We’ve tried both ways, and examined memory, and get varying event-not-found error messages in trying to use the returned data.

This is complicated by the fact that Studio::EventDescription has a private constructor. Which lead us to believe that it was intended as an array of Studio::EventDescription *, however, that doesn’t seem to work either. Any advice?

[RESOLVED] The root cause of the problem ended up being that the master bank and master bank string files were not loaded. There’s nothing explicit in the docs that says they’re required except a single line partway down the page on upgrading. And, it contradicts the one or two places that say that banks are monolithic (as opposed to the old fev/fsb relationship) and you don’t need to load anything else.

I believe that the array of pointers needs to be allocated, something like this:

int maxLen = 255;
char buffer[maxLen + 1];

Studio::Bank* bank = [[existing bank]];
//  iterate the events in this Bank
int eventCount = 0;
if (FMOD_ErrorCheck(bank->getEventCount(&eventCount)))
{
    Studio::EventDescription** array = (Studio::EventDescription**)malloc(eventCount * sizeof(void*));
    
    if (FMOD_ErrorCheck(bank->getEventList(array, eventCount, &eventCount)))
    {
        for (int i = 0; i < eventCount; i++) {
            if (FMOD_ErrorCheck(array[i]->getPath(buffer, maxLen, 0)))
            {
                CCLOG("Found event: %s", buffer);
            }
            else
            {
                CCLOG("Unable to determine event details");
            }
        }
    }
    free(array);
}

Pretty much all of the FMOD methods that return lists work the same way.

It would be good if they could include a code snippet similar to the above in the documentation because I, too, spent quite some time figuring it out.

PS: You are correct when you say that the EventDescription constructor is private, so we can’t instantiate them ourselves manually

Hope that helps

1 Like

The root cause of the problem ended up being that the master bank and master bank string files were not loaded. There’s nothing explicit in the docs that says they’re required except a single line partway down the page on upgrading. And, it contradicts the one or two places that say that banks are monolithic (as opposed to the old fev/fsb relationship) and you don’t need to load anything else.

1 Like