How to create the FMOD_STUDIO_EVENTDESCRIPTION array for use in FMOD_Studio_Bank_GetEventList() (FMOD Studio C API)

I have loaded a bank and want to iterate through all the events it contains. From the documentation, it looks like I should use FMOD_Studio_Bank_GetEventCount() to get the count of the events and use this count to create a buffer to pass to FMOD_Studio_Bank_GetEventList() to retrieve an array of FMOD_STUDIO_EVENTDESCRIPTIONs.

However, FMOD_STUDIO_EVENTDESCRIPTION is defined in fmod_studio_common.h as

typedef struct FMOD_STUDIO_EVENTDESCRIPTION FMOD_STUDIO_EVENTDESCRIPTION;

i.e. an incomplete type. Therefore the compiler gives an error when trying to use

sizeof(FMOD_STUDIO_EVENTDESCRIPTION)

or

FMOD_STUDIO_EVENTDESCRIPTION array[count];

because it can’t determine the size of the FMOD_STUDIO_EVENTDESCRIPTION type.

So how are people creating buffers/arrays to use with this function? Am I missing something in the documentation?

Thanks, Jim

Hi Jim,

This is more of a C/C++ type question to do with allocating the memory needed for the array of event descriptions.

int i;
sfxBank->getEventCount(&i);
const int list = i;
FMOD::Studio::EventDescription** eventList = new FMOD::Studio::EventDescription*[list];
sfxBank->getEventList(eventList, i, &i);

You need to make the event description array and array of pointers for it to work.

Thanks,
Richard

Hi Richard, Thanks for your answer, however I am using the C API, not the C++ API. In the C++ headers the EventDescription class is fully declared so

new FMOD::Studio::EventDescription*[list];
will allocate the required memory for the array. In the C headers, the FMOD_STUDIO_EVENTDESCRIPTION type is not fully declared, therefore there is no way for the compiler to know the size of the type, and therefore no way to allocate the memory.

Hi Jim,

Sorry, missed that part. Yes, there’s no “new” in C so you can use this instead:

FMOD_STUDIO_EVENTDESCRIPTION** eventList = (FMOD_STUDIO_EVENTDESCRIPTION**)malloc(sizeof(FMOD_STUDIO_EVENTDESCRIPTION*) * i);
1 Like

Ah, I see. It is only required to allocation memory for the pointers to the descriptions, not the descriptions themselves. Thanks!