try to fix sound leaks
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@12222 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
2ce395ba0d
commit
78d964b79d
@ -266,7 +266,8 @@ SFXBuffer* SFXManager::loadSingleSfx(const XMLNode* node,
|
||||
* \param id Identifier of the sound effect to create.
|
||||
*/
|
||||
SFXBase* SFXManager::createSoundSource(SFXBuffer* buffer,
|
||||
const bool add_to_SFX_list)
|
||||
const bool add_to_SFX_list,
|
||||
const bool owns_buffer)
|
||||
{
|
||||
bool positional = false;
|
||||
|
||||
@ -282,9 +283,9 @@ SFXBase* SFXManager::createSoundSource(SFXBuffer* buffer,
|
||||
|
||||
#if HAVE_OGGVORBIS
|
||||
assert( alIsBuffer(buffer->getBufferID()) );
|
||||
SFXBase* sfx = new SFXOpenAL(buffer, positional, buffer->getGain());
|
||||
SFXBase* sfx = new SFXOpenAL(buffer, positional, buffer->getGain(), owns_buffer);
|
||||
#else
|
||||
SFXBase* sfx = new DummySFX(buffer, positional, buffer->getGain());
|
||||
SFXBase* sfx = new DummySFX(buffer, positional, buffer->getGain(), owns_buffer);
|
||||
#endif
|
||||
|
||||
sfx->volume(m_master_gain);
|
||||
|
@ -117,7 +117,8 @@ public:
|
||||
float gain);
|
||||
|
||||
SFXBase* createSoundSource(SFXBuffer* info,
|
||||
const bool addToSFXList=true);
|
||||
const bool addToSFXList=true,
|
||||
const bool owns_buffer=false);
|
||||
SFXBase* createSoundSource(const std::string &name,
|
||||
const bool addToSFXList=true);
|
||||
|
||||
|
@ -35,7 +35,7 @@
|
||||
#include "config/user_config.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
|
||||
SFXOpenAL::SFXOpenAL(SFXBuffer* buffer, bool positional, float gain) : SFXBase()
|
||||
SFXOpenAL::SFXOpenAL(SFXBuffer* buffer, bool positional, float gain, bool ownsBuffer) : SFXBase()
|
||||
{
|
||||
m_soundBuffer = buffer;
|
||||
m_soundSource = 0;
|
||||
@ -44,6 +44,7 @@ SFXOpenAL::SFXOpenAL(SFXBuffer* buffer, bool positional, float gain) : SFXBase()
|
||||
m_defaultGain = gain;
|
||||
m_loop = false;
|
||||
m_gain = -1.0f;
|
||||
m_owns_buffer = ownsBuffer;
|
||||
|
||||
// Don't initialise anything else if the sfx manager was not correctly
|
||||
// initialised. First of all the initialisation will not work, and it
|
||||
@ -62,6 +63,12 @@ SFXOpenAL::~SFXOpenAL()
|
||||
{
|
||||
alDeleteSources(1, &m_soundSource);
|
||||
}
|
||||
|
||||
if (m_owns_buffer && m_soundBuffer != NULL)
|
||||
{
|
||||
m_soundBuffer->unload();
|
||||
delete m_soundBuffer;
|
||||
}
|
||||
} // ~SFXOpenAL
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -55,8 +55,11 @@ private:
|
||||
sounds later. */
|
||||
float m_gain;
|
||||
|
||||
bool m_owns_buffer;
|
||||
|
||||
public:
|
||||
SFXOpenAL(SFXBuffer* buffer, bool positional, float gain);
|
||||
SFXOpenAL(SFXBuffer* buffer, bool positional, float gain,
|
||||
bool owns_buffer = false);
|
||||
virtual ~SFXOpenAL();
|
||||
|
||||
/** Late creation, if SFX was initially disabled */
|
||||
|
@ -161,7 +161,7 @@ TrackObject::TrackObject(const XMLNode &xml_node)
|
||||
volume);
|
||||
buffer->load();
|
||||
|
||||
m_sound = sfx_manager->createSoundSource(buffer);
|
||||
m_sound = sfx_manager->createSoundSource(buffer, true, true);
|
||||
if (m_sound != NULL)
|
||||
{
|
||||
m_sound->position(m_init_xyz);
|
||||
@ -385,7 +385,7 @@ TrackObject::~TrackObject()
|
||||
|
||||
if (m_sound)
|
||||
{
|
||||
delete m_sound->getBuffer();
|
||||
//delete m_sound->getBuffer();
|
||||
sfx_manager->deleteSFX(m_sound);
|
||||
}
|
||||
} // ~TrackObject
|
||||
|
Loading…
Reference in New Issue
Block a user