Skip to content

Commit 93ad672

Browse files
author
natural-law
committed
the effect can be played and clear some memory leak
1 parent 8934ebc commit 93ad672

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

CocosDenshion/SimpleAudioEngine/SimpleAudioEngine.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ void SimpleAudioEngine::unloadEffect(int nSoundId)
205205

206206
delete [] (pElement->pDataBuffer);
207207
HASH_DEL(m_pEffects, pElement);
208+
free(pElement);
208209
} while (0);
209210
}
210211

@@ -235,6 +236,9 @@ void SimpleAudioEngine::playPreloadedEffect(int nSoundId)
235236
{
236237
pPlayer = new SoundPlayer();
237238
m_EffectPlayers.push_back(pPlayer);
239+
240+
// set the player volume
241+
pPlayer->SetVolumeValue(m_nEffectsVolume);
238242
}
239243
}
240244

@@ -248,9 +252,9 @@ void SimpleAudioEngine::removeAllEffects()
248252
{
249253
for (tHashElement *pElement = m_pEffects; pElement != NULL; )
250254
{
251-
unsigned char* pData = pElement->pDataBuffer;
252-
delete [] pData;
255+
int nSoundID = pElement->nSoundID;
253256
pElement = (tHashElement*)pElement->hh.next;
257+
unloadEffect(nSoundID);
254258
}
255259
}
256260

TestAudioEngine/TestAudioEngineMainForm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Boolean TMainForm::CtrlSelected(TApplication * pApp, EventType * pEvent)
9292

9393
case TESTAU_ID_Form1002_LoadEffect:
9494
// load effect1
95-
m_nEffect1ID = pAudioEngine->preloadEffect(/*s_Effect1File*/s_BackgroundFile);
95+
m_nEffect1ID = pAudioEngine->preloadEffect(s_Effect1File);
9696
assert(m_nEffect1ID > 0);
9797
bHandled = TRUE;
9898
break;

0 commit comments

Comments
 (0)