fix AudioEngine maybe crash on android (#20361)

* fix AudioEngine maybe crash on android

I receive many crash about std::base_string in bugly(tencent) crash report, i can't prove those crash is relate with this, but when after  fix, i never receive again. so i think there maybe some situation will cause crash.

* type of 'filePath' change to std::string
This commit is contained in:
codetypes 2019-11-23 10:00:16 +08:00 committed by minggo
parent 191b2b8982
commit 9b8a72a843
4 changed files with 6 additions and 7 deletions

View File

@ -65,8 +65,7 @@ AudioEngine::AudioEngineThreadPool* AudioEngine::s_threadPool = nullptr;
bool AudioEngine::_isEnabled = true;
AudioEngine::AudioInfo::AudioInfo()
: filePath(nullptr)
, profileHelper(nullptr)
: profileHelper(nullptr)
, volume(1.0f)
, loop(false)
, duration(TIME_UNKNOWN)
@ -241,7 +240,7 @@ int AudioEngine::play2d(const std::string& filePath, bool loop, float volume, co
auto& audioRef = _audioIDInfoMap[ret];
audioRef.volume = volume;
audioRef.loop = loop;
audioRef.filePath = &it->first;
audioRef.filePath = it->first;
if (profileHelper) {
profileHelper->lastPlayTime = utils::gettime();
@ -342,7 +341,7 @@ void AudioEngine::remove(int audioID)
if (it->second.profileHelper) {
it->second.profileHelper->audioIDs.remove(audioID);
}
_audioPathIDMap[*it->second.filePath].remove(audioID);
_audioPathIDMap[it->second.filePath].remove(audioID);
_audioIDInfoMap.erase(it);
}
}

View File

@ -672,7 +672,7 @@ void AudioEngineImpl::update(float dt)
std::string filePath;
if (player->_finishCallbak) {
auto& audioInfo = AudioEngine::_audioIDInfoMap[audioID];
filePath = *audioInfo.filePath;
filePath = audioInfo.filePath;
}
AudioEngine::remove(audioID);

View File

@ -326,7 +326,7 @@ protected:
struct AudioInfo
{
const std::string* filePath;
std::string filePath;
ProfileHelper* profileHelper;
float volume;

View File

@ -476,7 +476,7 @@ void AudioEngineImpl::update(float dt)
std::string filePath;
if (player->_finishCallbak) {
auto& audioInfo = AudioEngine::_audioIDInfoMap[audioID];
filePath = *audioInfo.filePath;
filePath = audioInfo.filePath;
}
AudioEngine::remove(audioID);