beautify error info

This commit is contained in:
Jare Guo
2017-09-01 00:04:13 +08:00
parent 94012eaed7
commit 76d0346af4
2 changed files with 55 additions and 16 deletions
+29 -9
View File
@@ -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 = {};
};
@@ -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);
};