FMOD_CHANNEL** channel = static_cast<FMOD_CHANNEL**>(realloc(channel, musicCountsizeof(FMOD_CHANNEL)));
Every time a music is added, a memory is dynamically allocated to channel array.
However, when I free the array like this, free(channel); the program crashes.
How can I handle this?
Hi, this doesn’t really seem to be FMOD related?
You are dynamically allocating memory to store the channels for your music, then freeing them, but i am assuming you’re still using the original pointer in some other part of the code that is causing the crash?
FMOD returns a pointer to a channel that is already allocated inside the fmod engine yourself. I’m not sure why you need to allocate memory to store a 4 or 8 byte pointer.
If you have multiple channels for music, you could just be storing an array of FMOD_CHANNEL pointers in a struct.
Allocating and freeing lots of little pieces of memory leads to memory fragmentation and bad performance.