This commit is contained in:
halx99 2020-07-30 17:07:38 +08:00
parent 58c4fb32c1
commit dda5628876
3 changed files with 13 additions and 1 deletions

View File

@ -41,6 +41,7 @@
#include "base/CCScheduler.h"
#include "platform/CCFileUtils.h"
#include "audio/include/AudioDecoderManager.h"
#include "audio/include/AudioPlayer.h"
using namespace cocos2d;
@ -494,6 +495,7 @@ void AudioEngineImpl::_updateLocked(float dt)
finishCallback(audioID, filePath); //FIXME: callback will delay 50ms
});
#endif
player->setCache(nullptr); // it's safe for player didn't free audio cache
}
delete player;
_alSourceUsed[alSource] = false;
@ -521,6 +523,10 @@ void AudioEngineImpl::uncache(const std::string &filePath)
void AudioEngineImpl::uncacheAll()
{
// prevent player hold invalid AudioCache* pointer, since all audio caches purged
for (auto& player : _audioPlayers)
player.second->setCache(nullptr);
_audioCaches.clear();
}

View File

@ -751,6 +751,7 @@ void AudioEngineImpl::_updateLocked(float dt)
_finishCallbacks.push_back([finishCallback = std::move(player->_finishCallbak), audioID, filePath = std::move(filePath)](){
finishCallback(audioID, filePath); // FIXME: callback will delay 50ms
});
player->setCache(nullptr); // it's safe for player didn't free audio cache
}
delete player;
@ -778,7 +779,11 @@ void AudioEngineImpl::uncache(const std::string &filePath)
}
void AudioEngineImpl::uncacheAll()
{
{
// prevent player hold invalid AudioCache* pointer, since all audio caches purged
for(auto& player : _audioPlayers)
player.second->setCache(nullptr);
_audioCaches.clear();
}

View File

@ -46,6 +46,7 @@ class AudioEngineImpl;
class CC_DLL AudioPlayer
{
friend class AudioEngineImpl;
public:
AudioPlayer();
~AudioPlayer();