Skip to content

Commit

Permalink
avoid releasing builtin asset (cocos#4915)
Browse files Browse the repository at this point in the history
refine
  • Loading branch information
holycanvas authored and 2youyou2 committed Jul 25, 2019
1 parent 5a31bf4 commit e227699
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions cocos2d/core/load-pipeline/CCLoader.js
Expand Up @@ -812,6 +812,7 @@ proto.release = function (asset) {
}
else if (asset) {
var id = this._getReferenceKey(asset);
if (!CC_EDITOR && id && id in cc.AssetLibrary.getBuiltinDeps()) return;
var item = this.getItem(id);
if (item) {
var removed = this.removeItem(id);
Expand Down
11 changes: 10 additions & 1 deletion cocos2d/core/platform/CCAssetLibrary.js
Expand Up @@ -399,6 +399,8 @@ let _builtins = {
material: {}
};

let _builtinDeps = {};

function loadBuiltins (name, type, cb) {
let dirname = name + 's';
let builtin = _builtins[name] = {};
Expand All @@ -413,7 +415,10 @@ function loadBuiltins (name, type, cb) {
}
else {
for (let i = 0; i < assets.length; i++) {
builtin[`${assets[i].name}`] = assets[i];
var asset = assets[i];
var deps = cc.loader.getDependsRecursively(asset);
deps.forEach(uuid => _builtinDeps[uuid] = true);
builtin[`${asset.name}`] = asset;
}
}

Expand Down Expand Up @@ -444,6 +449,10 @@ AssetLibrary.resetBuiltins = function () {
effect: {},
material: {}
};
_builtinDeps = {};
};
AssetLibrary.getBuiltinDeps = function () {
return _builtinDeps;
}

module.exports = cc.AssetLibrary = AssetLibrary;

0 comments on commit e227699

Please sign in to comment.