the effect can be played and clear some memory leak
This commit is contained in:
natural-law 2010-09-30 03:25:15 +00:00
parent 683596a023
commit 6d658b341c
2 changed files with 7 additions and 3 deletions

View File

@ -205,6 +205,7 @@ void SimpleAudioEngine::unloadEffect(int nSoundId)
delete [] (pElement->pDataBuffer); delete [] (pElement->pDataBuffer);
HASH_DEL(m_pEffects, pElement); HASH_DEL(m_pEffects, pElement);
free(pElement);
} while (0); } while (0);
} }
@ -235,6 +236,9 @@ void SimpleAudioEngine::playPreloadedEffect(int nSoundId)
{ {
pPlayer = new SoundPlayer(); pPlayer = new SoundPlayer();
m_EffectPlayers.push_back(pPlayer); m_EffectPlayers.push_back(pPlayer);
// set the player volume
pPlayer->SetVolumeValue(m_nEffectsVolume);
} }
} }
@ -248,9 +252,9 @@ void SimpleAudioEngine::removeAllEffects()
{ {
for (tHashElement *pElement = m_pEffects; pElement != NULL; ) for (tHashElement *pElement = m_pEffects; pElement != NULL; )
{ {
unsigned char* pData = pElement->pDataBuffer; int nSoundID = pElement->nSoundID;
delete [] pData;
pElement = (tHashElement*)pElement->hh.next; pElement = (tHashElement*)pElement->hh.next;
unloadEffect(nSoundID);
} }
} }

View File

@ -92,7 +92,7 @@ Boolean TMainForm::CtrlSelected(TApplication * pApp, EventType * pEvent)
case TESTAU_ID_Form1002_LoadEffect: case TESTAU_ID_Form1002_LoadEffect:
// load effect1 // load effect1
m_nEffect1ID = pAudioEngine->preloadEffect(/*s_Effect1File*/s_BackgroundFile); m_nEffect1ID = pAudioEngine->preloadEffect(s_Effect1File);
assert(m_nEffect1ID > 0); assert(m_nEffect1ID > 0);
bHandled = TRUE; bHandled = TRUE;
break; break;