I’m trying to figure out why my file handles to .fsb sound streams aren’t being closed. Below is a minimal example of the usage. Every time I call [PlayStream], it’s opening a file handle to the file specified, which is what I expect. HOWEVER, when I release the sound and stop the channel, the file handle still remains open. So if I were to call [PlayStream] 150 times, there would be 150 OS file handles open and I would also incur the ever-increasing memory usage associated with this as well. Main question: What is a way to properly close the .fsb file handle using the FMOD Low Level API? Do I have to close the file myself even though FMOD opens it for me?
FMOD_RESULT F_CALLBACK FMODMusicChannelCallback(FMOD_CHANNELCONTROL *pChanControl,
FMOD_CHANNELCONTROL_TYPE controlType,
FMOD_CHANNELCONTROL_CALLBACK_TYPE callbackType,
void *commandData1, void *commandData2) {
switch(controlType) {
case FMOD_CHANNELCONTROL_CHANNEL:
{
if(callbackType == FMOD_CHANNELCONTROL_CALLBACK_END) {
FMOD::Channel *pChannel = reinterpret_cast<FMOD::Channel*>(pChanControl);
FMOD::Sound *pSound;
pChannel->stop();
pChannel->getCurrentSound(&pSound);
pSound->release();
}
}
}
}
void FrameUpdate() {
mpFMODSystem->Update();
}
void PlayStream(unsigned int subsoundID) {
FMOD::Sound *pBaseSound, *pSubSound;
FMOD::Channel *pChannel;
mpFMODSystem->createStream("soundbankwithsubsounds.fsb", FMOD_LOOP_OFF|FMOD_2D, NULL, &pBaseSound);
pBaseSound->getSubSound(subsoundID, &pSubSound);
mpFMODSystem->playSound(pSubSound, NULL, false, &pChannel);
pChannel->setCallback(FMODMusicChannelCallback);
}