[SOLVED] Shared buffer's reference count not incremented


04-06-2014 20:41:58

The OgreOggSound::sharedAudioBuffer struct is being used to share buffers across multiple sounds and has a reference count that is supposed to make sure it stays alive as long as it is being used by a sound. Currently, the reference count is set to one when the OgreOggSound::sharedAudioBuffer struct is created, but it is never incremented after that, only decremented. This is causing files to be constantly loaded and freed when they should be staying alive for pretty much the entire duration of the application.

I've modified OgreOggSoundManager::_loadSoundImpl() to increment the mRefCount whenever a buffer is retrieved and passed to the loaded sound, which fixes the issue but exposes another problem. The OgreOggSound::sharedAudioBuffer struct holds a pointer to the original OgreOggISound that it was created for, once that OgreOggISound is destroyed then it will be passing around a deleted pointer which causes it to crash. This means that OgreOggSound::sharedAudioBuffer has to be changed to not store the OgreOggISound pointer, but to only store copies of the data that needs to be passed around. I've made both of these changes and you can get the patch file from here. Let me know if there's any problem with it.