Menu

#8 Crash caused by running out of file handles

Latest SVN
closed-fixed
None
5
2014-07-07
2014-06-06
Shenjoku
No

If you try to create a lot of sounds in rapid succession it is possible for the application to run out of available file handles. This problem only occurs when multi-threading is turned on. The reason for this is that in OgreOggSoundManager::_createSoundImpl() it is always opening the file stream upfront and then adding it to the action queue for handling later, even if the file has already been opened and there's a shared stream available for use. So if you create sounds faster than the sound thread can handle them then it's possible to fill the queue with file handles and eventually run out, causing an exception to be thrown.

In order to fix this problem I have moved the code that is opening the file stream out of OgreOggSoundManager::_createSoundImpl() and into a new function, OgreOggSoundManager::_openStream(). OgreOggSoundManager::_openStream() is then being called in OgreOggSoundManager::_loadSoundImpl() only if there is not a shared buffer available. This not only fixes the crash but also makes the code more efficient since it no longer bothers opening the file unless it absolutely has to. This also moves the file opening to a separate thread, which means less chance of blocking the main thread when calling OgreOggSoundManager::createSound(), so that's another big win.

Unfortunately, this requires adding another mutex in order to guard the mResourceGroupName from being modified in a separate thread, which also changes the interface of getResourceGroupName() since it can no longer return a const reference.

The patch file with the changes is attached.

1 Attachments

Discussion

  • Shenjoku

    Shenjoku - 2014-06-30

    Updated the patch file to work with the latest code.

     
  • Stickymango

    Stickymango - 2014-07-07
    • status: open --> accepted
     
  • Stickymango

    Stickymango - 2014-07-07
    • status: accepted --> closed-fixed
     

Log in to post a comment.