3d gfx 2 4 3 patch (#2984)

* free AudioMix partial wake locks, and android device can enter power save

* fix audio engine crash, avoid update function reentrancy.

* fix hot update issue.

* avoid a NULL point crash when ScriptEngine::cleanup
This commit is contained in:
kenshin
2020-11-06 18:03:49 +08:00
committed by GitHub
parent 6ef6f267b1
commit 2ad036ba09
6 changed files with 104 additions and 40 deletions
+12
View File
@@ -362,6 +362,12 @@ void AudioEngine::onEnterBackground(const CustomEvent &event) {
_breakAudioID.push_back(it->first);
}
}
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
if (_audioEngineImpl) {
_audioEngineImpl->onPause();
}
#endif
}
void AudioEngine::onEnterForeground(const CustomEvent &event) {
@@ -370,6 +376,12 @@ void AudioEngine::onEnterForeground(const CustomEvent &event) {
_audioEngineImpl->resume(*it);
}
_breakAudioID.clear();
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
if (_audioEngineImpl) {
_audioEngineImpl->onResume();
}
#endif
}
void AudioEngine::stop(int audioID)
@@ -429,4 +429,20 @@ void AudioEngineImpl::uncacheAll()
}
}
void AudioEngineImpl::onPause()
{
if (_audioPlayerProvider != nullptr)
{
_audioPlayerProvider->pause();
}
}
void AudioEngineImpl::onResume()
{
if (_audioPlayerProvider != nullptr)
{
_audioPlayerProvider->resume();
}
}
#endif
@@ -73,6 +73,9 @@ public:
void uncacheAll();
void preload(const std::string& filePath, const std::function<void(bool)>& callback);
void onResume();
void onPause();
void setAudioFocusForAllPlayers(bool isFocus);
private:
// engine interfaces
+8 -3
View File
@@ -687,9 +687,14 @@ void AudioEngineImpl::update(float dt)
_threadMutex.lock();
it = _audioPlayers.erase(it);
_threadMutex.unlock();
if (player->_finishCallbak) {
player->_finishCallbak(audioID, filePath); //IDEA: callback will delay 50ms
if(auto sche = _scheduler.lock()) {
if (player->_finishCallbak) {
auto cb = player->_finishCallbak;
sche->performFunctionInCocosThread([audioID, cb, filePath](){
cb(audioID, filePath); //IDEA: callback will delay 50ms
});
}
}
delete player;
@@ -294,7 +294,7 @@ namespace se {
thiz->_isErrorHandleWorking = true;
Value errorHandler;
if (thiz->_globalObj->getProperty("__errorHandler", &errorHandler) && errorHandler.isObject() && errorHandler.toObject()->isFunction())
if (thiz->_globalObj && thiz->_globalObj->getProperty("__errorHandler", &errorHandler) && errorHandler.isObject() && errorHandler.toObject()->isFunction())
{
ValueArray args;
args.push_back(resouceNameVal);
@@ -699,20 +699,8 @@ void AssetsManagerEx::parseVersion()
}
else
{
_updateState = State::NEED_UPDATE;
// Wait to update so continue the process
if (_updateEntry == UpdateEntry::DO_UPDATE)
{
// dispatch after checking update entry because event dispatching may modify the update entry
dispatchUpdateEvent(EventAssetsManagerEx::EventCode::NEW_VERSION_FOUND);
_updateState = State::PREDOWNLOAD_MANIFEST;
downloadManifest();
}
else
{
dispatchUpdateEvent(EventAssetsManagerEx::EventCode::NEW_VERSION_FOUND);
}
_updateState = State::PREDOWNLOAD_MANIFEST;
downloadManifest();
}
}
}
@@ -763,12 +751,17 @@ void AssetsManagerEx::parseManifest()
else
{
_updateState = State::NEED_UPDATE;
dispatchUpdateEvent(EventAssetsManagerEx::EventCode::NEW_VERSION_FOUND);
if (_updateEntry == UpdateEntry::DO_UPDATE)
{
startUpdate();
}
else if (_updateEntry == UpdateEntry::CHECK_UPDATE)
{
prepareUpdate();
}
dispatchUpdateEvent(EventAssetsManagerEx::EventCode::NEW_VERSION_FOUND);
}
}
}
@@ -795,6 +788,16 @@ void AssetsManagerEx::prepareUpdate()
_tempManifest->genResumeAssetsList(&_downloadUnits);
_totalWaitToDownload = _totalToDownload = (int)_downloadUnits.size();
_downloadResumed = true;
// Collect total size
for(auto iter : _downloadUnits)
{
const DownloadUnit& unit = iter.second;
if (unit.size > 0)
{
_totalSize += unit.size;
}
}
}
else
{
@@ -828,21 +831,17 @@ void AssetsManagerEx::prepareUpdate()
for (auto it = diff_map.begin(); it != diff_map.end(); ++it)
{
Manifest::AssetDiff diff = it->second;
if (diff.type == Manifest::DiffType::DELETED)
{
std::string exsitedPath = _storagePath + diff.asset.path;
_fileUtils->removeFile(exsitedPath);
}
else
if (diff.type != Manifest::DiffType::DELETED)
{
std::string path = diff.asset.path;
DownloadUnit unit;
unit.customId = it->first;
unit.srcUrl = packageUrl + path;
unit.srcUrl = packageUrl + path + "?md5=" + diff.asset.md5;
unit.storagePath = _tempStoragePath + path;
unit.size = diff.asset.size;
_downloadUnits.emplace(unit.customId, unit);
_tempManifest->setAssetDownloadState(it->first, Manifest::DownloadState::UNSTARTED);
_totalSize += unit.size;
}
}
// Start updating the temp manifest
@@ -864,6 +863,7 @@ void AssetsManagerEx::startUpdate()
}
if (_updateState == State::READY_TO_UPDATE)
{
_totalSize = 0;
_updateState = State::UPDATING;
std::string msg;
if (_downloadResumed)
@@ -882,12 +882,20 @@ void AssetsManagerEx::startUpdate()
void AssetsManagerEx::updateSucceed()
{
// Set temp manifest's updating
_tempManifest->setUpdating(false);
if (_tempManifest != nullptr) {
_tempManifest->setUpdating(false);
}
// Every thing is correctly downloaded, do the following
// 1. rename temporary manifest to valid manifest
_fileUtils->renameFile(_tempStoragePath, TEMP_MANIFEST_FILENAME, MANIFEST_FILENAME);
// 2. merge temporary storage path to storage path so that temporary version turns to cached version
if (_fileUtils->isFileExist(_tempManifestPath)) {
_fileUtils->renameFile(_tempStoragePath, TEMP_MANIFEST_FILENAME, MANIFEST_FILENAME);
}
// 2. Get the delete files
std::unordered_map<std::string, Manifest::AssetDiff> diff_map = _localManifest->genDiff(_remoteManifest);
// 3. merge temporary storage path to storage path so that temporary version turns to cached version
if (_fileUtils->isDirectoryExist(_tempStoragePath))
{
// Merging all files in temp storage path to storage path
@@ -913,21 +921,40 @@ void AssetsManagerEx::updateSucceed()
}
_fileUtils->renameFile(*it, dstPath);
}
// Remove from delete list for safe, although this is not the case in general.
auto diff_itr = diff_map.find(relativePath);
if (diff_itr != diff_map.end()) {
diff_map.erase(diff_itr);
}
}
// Preprocessing local files in previous version and creating download folders
for (auto it = diff_map.begin(); it != diff_map.end(); ++it)
{
Manifest::AssetDiff diff = it->second;
if (diff.type == Manifest::DiffType::DELETED)
{
// TODO: Do this when download finish, it don’t matter delete or not.
std::string exsitedPath = _storagePath + diff.asset.path;
_fileUtils->removeFile(exsitedPath);
}
}
// Remove temp storage path
_fileUtils->removeDirectory(_tempStoragePath);
}
// 3. swap the localManifest
// 4. swap the localManifest
CC_SAFE_RELEASE(_localManifest);
_localManifest = _remoteManifest;
_localManifest->setManifestRoot(_storagePath);
_remoteManifest = nullptr;
// 4. make local manifest take effect
// 5. make local manifest take effect
prepareLocalManifest();
// 5. Set update state
// 6. Set update state
_updateState = State::UP_TO_DATE;
// 6. Notify finished event
// 7. Notify finished event
dispatchUpdateEvent(EventAssetsManagerEx::EventCode::UPDATE_FINISHED);
// 8. Remove temp storage path
_fileUtils->removeDirectory(_tempStoragePath);
}
void AssetsManagerEx::checkUpdate()
@@ -1024,6 +1051,7 @@ void AssetsManagerEx::update()
}
break;
case State::FAIL_TO_UPDATE:
case State::READY_TO_UPDATE:
case State::NEED_UPDATE:
{
// Manifest not loaded yet
@@ -1032,7 +1060,7 @@ void AssetsManagerEx::update()
_updateState = State::PREDOWNLOAD_MANIFEST;
downloadManifest();
}
else
else if (_updateEntry == UpdateEntry::DO_UPDATE)
{
startUpdate();
}
@@ -1319,12 +1347,12 @@ void AssetsManagerEx::queueDowload()
void AssetsManagerEx::onDownloadUnitsFinished()
{
// Always save current download manifest information for resuming
_tempManifest->saveToFile(_tempManifestPath);
// Finished with error check
if (_failedUnits.size() > 0)
{
// Save current download manifest information for resuming
_tempManifest->saveToFile(_tempManifestPath);
_updateState = State::FAIL_TO_UPDATE;
dispatchUpdateEvent(EventAssetsManagerEx::EventCode::UPDATE_FAILED);
}