@wangfuguii 写道:
最近测试 AssetsManagerEx 的时候发现有几个无法理解的行为,想请教引擎组的大大。
1,下载资源清单文件失败后,state 不会变化到 UNCHECKED,导致不能重试 update 方法:
可以看到如果读取不到资源清单的 url 会切换状态到 UNCHECKED 并且发送 ERROR_DOWNLOAD_MANIFEST 事件:
void AssetsManagerEx::downloadManifest() { if (_updateState != State::PREDOWNLOAD_MANIFEST) return; std::string manifestUrl = _localManifest->getManifestFileUrl(); if (manifestUrl.size() > 0) { _updateState = State::DOWNLOADING_MANIFEST; // Download version file asynchronously _downloader->createDownloadFileTask(manifestUrl, _tempManifestPath, MANIFEST_ID); } // No manifest file found else { CCLOG("AssetsManagerEx : No manifest file found, check update failed\n"); dispatchUpdateEvent(EventAssetsManagerEx::EventCode::ERROR_DOWNLOAD_MANIFEST); _updateState = State::UNCHECKED; } }
但是在下载错误的回调方法中只是发送了 ERROR_DOWNLOAD_MANIFEST 事件后并没有切换状态,也没有接着发送UPDATE_FAILED 事件,其设计是下载资源清单失败后 hang 在这里吗?
void AssetsManagerEx::onError(const network::DownloadTask& task, int errorCode, int errorCodeInternal, const std::string& errorStr) { // Skip version error occurred if (task.identifier == VERSION_ID) { CCLOG("AssetsManagerEx : Fail to download version file, step skipped\n"); _updateState = State::PREDOWNLOAD_MANIFEST; downloadManifest(); } else if (task.identifier == MANIFEST_ID) { dispatchUpdateEvent(EventAssetsManagerEx::EventCode::ERROR_DOWNLOAD_MANIFEST, task.identifier, errorStr, errorCode, errorCodeInternal); } else { auto unitIt = _downloadUnits.find(task.identifier); // Found unit and add it to failed units if (unitIt != _downloadUnits.end()) { _totalWaitToDownload--; DownloadUnit unit = unitIt->second; _failedUnits.emplace(unit.customId, unit); } dispatchUpdateEvent(EventAssetsManagerEx::EventCode::ERROR_UPDATING, task.identifier, errorStr, errorCode, errorCodeInternal); } }
2,我在 checkUpdate 后如果收到 NEW_VERSION_FOUND 后会立即调用 update 方法,在 Mac 平台上,会出现提示 More than one download file task write to same file: ...,也能收到 ERROR_DOWNLOAD_MANIFEST 通知,但是到了这一步之后更新流程并没有中断,随后又会下载资源清单文件,这是我的日志:
Simulator: check update 尚未检查是否存在新版本 Simulator: get state 正在下载版本manifest文件 Simulator: get event code 更新过程的进度事件 Simulator: Processing 100.00% Simulator: get state 检查到新版本,需要更新 Simulator: get event code 找到新版本 Simulator: New version found Simulator: found new version, call update Simulator: Fail to download manifest file, hot update skipped. Simulator: update finished, null More than one download file task write to same file:/Applications/CocosCreator.app/... Simulator: get state 正在下载资源manifest文件 Simulator: get event code 更新过程的进度事件
通过阅读源码发现是 DownloadTaskCURL 的
// include platform specific implement class #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) #include "network/CCDownloader-apple.h" #include "network/CCDownloader-curl.h" #define DownloaderImpl DownloaderCURL ... if (_sStoragePathSet.end() != _sStoragePathSet.find(_tempFileName)) { // there is another task uses this storage path _errCode = DownloadTask::ERROR_FILE_OP_FAILED; _errCodeInternal = 0; _errDescription = "More than one download file task write to same file:"; _errDescription.append(_tempFileName); return false; } _sStoragePathSet.insert(_tempFileName);
帖子: 3
参与者: 1