From 76d0346af4dac2fffa7d852c02159f8c8a013d64 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Fri, 1 Sep 2017 00:04:13 +0800 Subject: [PATCH] beautify error info --- cocos2d/core/load-pipeline/asset-table.js | 38 ++++++++++++++----- .../load-pipeline/released-asset-checker.js | 33 ++++++++++++---- 2 files changed, 55 insertions(+), 16 deletions(-) diff --git a/cocos2d/core/load-pipeline/asset-table.js b/cocos2d/core/load-pipeline/asset-table.js index 20b734877b..e2feb81d94 100644 --- a/cocos2d/core/load-pipeline/asset-table.js +++ b/cocos2d/core/load-pipeline/asset-table.js @@ -110,15 +110,15 @@ proto.getUuidArray = function (path, type, out_urls) { return uuids; }; -/** - * !#en Returns all asset paths in the table. - * !#zh 返回表中的所有资源路径。 - * @method getAllPaths - * @return {string[]} - */ -proto.getAllPaths = function () { - return Object.keys(this._pathToUuid); -}; +// /** +// * !#en Returns all asset paths in the table. +// * !#zh 返回表中的所有资源路径。 +// * @method getAllPaths +// * @return {string[]} +// */ +// proto.getAllPaths = function () { +// return Object.keys(this._pathToUuid); +// }; /** * !#en TODO @@ -138,6 +138,26 @@ proto.add = function (path, uuid, type, isMainAsset) { pushToMap(this._pathToUuid, path, newEntry, isMainAsset); }; +proto.getInfo_DEBUG = CC_DEBUG && function (uuid) { + var path2uuid = this._pathToUuid; + var paths = Object.keys(path2uuid); + for (var p = 0; p < paths.length; ++p) { + var path = paths[p]; + var item = path2uuid[path]; + if (Array.isArray(item)) { + for (var i = 0; i < item.length; i++) { + var entry = item[i]; + if (entry.uuid === uuid) { + return { path: path, type: entry.type }; + } + } + } + else if (item.uuid === uuid) { + return { path: path, type: item.type }; + } + } +}; + proto.reset = function () { this._pathToUuid = {}; }; diff --git a/cocos2d/core/load-pipeline/released-asset-checker.js b/cocos2d/core/load-pipeline/released-asset-checker.js index 35adf56c43..142ff3144f 100644 --- a/cocos2d/core/load-pipeline/released-asset-checker.js +++ b/cocos2d/core/load-pipeline/released-asset-checker.js @@ -42,17 +42,25 @@ ReleasedAssetChecker.prototype.setReleased = function (item, releasedKey) { }; function getItemDesc (item) { - var desc = item.rawUrl; if (item.uuid) { - desc += `(${item.uuid})`; + var info = cc.loader._resources.getInfo_DEBUG(item.uuid); + if (info) { + info.path = 'resources/' + info.path; + return `"${info.path}" (type: ${JS.getClassName(info.type)}, uuid: ${item.uuid})`; + } + else { + return `"${item.rawUrl}" (${item.uuid})`; + } + } + else { + return `"${item.rawUrl}"`; } - return desc; } function doCheckCouldRelease (releasedKey, refOwnerItem, caches) { var loadedAgain = caches[releasedKey]; if (!loadedAgain) { - cc.warn(`${releasedKey} was released but still referenced by ${getItemDesc(refOwnerItem)}`); + cc.log(`"${releasedKey}" was released but maybe still referenced by ${getItemDesc(refOwnerItem)}`); } } @@ -65,16 +73,16 @@ ReleasedAssetChecker.prototype.checkCouldRelease = function (caches) { var released = this._releasedKeys; - // touch dependencies + // check loader cache for (let id in caches) { var item = caches[id]; if (item.alias) { item = item.alias; } - var depends = item.dependKeys; + let depends = item.dependKeys; if (depends) { for (let i = 0; i < depends.length; ++i) { - var depend = depends[i]; + let depend = depends[i]; if (released[depend]) { doCheckCouldRelease(depend, item, caches); delete released[depend]; @@ -82,6 +90,17 @@ ReleasedAssetChecker.prototype.checkCouldRelease = function (caches) { } } } + + // // check current scene + // let depends = cc.director.getScene().dependAssets; + // for (let i = 0; i < depends.length; ++i) { + // let depend = depends[i]; + // if (released[depend]) { + // doCheckCouldRelease(depend, item, caches); + // delete released[depend]; + // } + // } + // clear released JS.clear(released); };