mirror of https://github.com/axmolengine/axmol.git
Sync missing fixs from v3, see: https://github.com/cocos2d/cocos2d-x/pull/19240
This commit is contained in:
parent
58c4fb32c1
commit
dda5628876
|
@ -41,6 +41,7 @@
|
||||||
#include "base/CCScheduler.h"
|
#include "base/CCScheduler.h"
|
||||||
#include "platform/CCFileUtils.h"
|
#include "platform/CCFileUtils.h"
|
||||||
#include "audio/include/AudioDecoderManager.h"
|
#include "audio/include/AudioDecoderManager.h"
|
||||||
|
#include "audio/include/AudioPlayer.h"
|
||||||
|
|
||||||
using namespace cocos2d;
|
using namespace cocos2d;
|
||||||
|
|
||||||
|
@ -494,6 +495,7 @@ void AudioEngineImpl::_updateLocked(float dt)
|
||||||
finishCallback(audioID, filePath); //FIXME: callback will delay 50ms
|
finishCallback(audioID, filePath); //FIXME: callback will delay 50ms
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
|
player->setCache(nullptr); // it's safe for player didn't free audio cache
|
||||||
}
|
}
|
||||||
delete player;
|
delete player;
|
||||||
_alSourceUsed[alSource] = false;
|
_alSourceUsed[alSource] = false;
|
||||||
|
@ -521,6 +523,10 @@ void AudioEngineImpl::uncache(const std::string &filePath)
|
||||||
|
|
||||||
void AudioEngineImpl::uncacheAll()
|
void AudioEngineImpl::uncacheAll()
|
||||||
{
|
{
|
||||||
|
// prevent player hold invalid AudioCache* pointer, since all audio caches purged
|
||||||
|
for (auto& player : _audioPlayers)
|
||||||
|
player.second->setCache(nullptr);
|
||||||
|
|
||||||
_audioCaches.clear();
|
_audioCaches.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -751,6 +751,7 @@ void AudioEngineImpl::_updateLocked(float dt)
|
||||||
_finishCallbacks.push_back([finishCallback = std::move(player->_finishCallbak), audioID, filePath = std::move(filePath)](){
|
_finishCallbacks.push_back([finishCallback = std::move(player->_finishCallbak), audioID, filePath = std::move(filePath)](){
|
||||||
finishCallback(audioID, filePath); // FIXME: callback will delay 50ms
|
finishCallback(audioID, filePath); // FIXME: callback will delay 50ms
|
||||||
});
|
});
|
||||||
|
player->setCache(nullptr); // it's safe for player didn't free audio cache
|
||||||
}
|
}
|
||||||
|
|
||||||
delete player;
|
delete player;
|
||||||
|
@ -779,6 +780,10 @@ void AudioEngineImpl::uncache(const std::string &filePath)
|
||||||
|
|
||||||
void AudioEngineImpl::uncacheAll()
|
void AudioEngineImpl::uncacheAll()
|
||||||
{
|
{
|
||||||
|
// prevent player hold invalid AudioCache* pointer, since all audio caches purged
|
||||||
|
for(auto& player : _audioPlayers)
|
||||||
|
player.second->setCache(nullptr);
|
||||||
|
|
||||||
_audioCaches.clear();
|
_audioCaches.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ class AudioEngineImpl;
|
||||||
|
|
||||||
class CC_DLL AudioPlayer
|
class CC_DLL AudioPlayer
|
||||||
{
|
{
|
||||||
|
friend class AudioEngineImpl;
|
||||||
public:
|
public:
|
||||||
AudioPlayer();
|
AudioPlayer();
|
||||||
~AudioPlayer();
|
~AudioPlayer();
|
||||||
|
|
Loading…
Reference in New Issue