From 858fb30a1471f11f0570a377ade9174d5960a513 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Mon, 26 Jun 2017 17:56:56 +0800 Subject: [PATCH] Fix circle reference check issue --- cocos2d/core/load-pipeline/CCLoader.js | 8 +------- cocos2d/core/load-pipeline/loading-items.js | 13 ++++++++++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cocos2d/core/load-pipeline/CCLoader.js b/cocos2d/core/load-pipeline/CCLoader.js index d022891a30..237ef42c10 100644 --- a/cocos2d/core/load-pipeline/CCLoader.js +++ b/cocos2d/core/load-pipeline/CCLoader.js @@ -261,10 +261,6 @@ proto.load = function(resources, progressCallback, completeCallback) { }; proto.flowInDeps = function (owner, urlList, callback) { - if (owner && !owner.deps) { - owner.deps = []; - } - _sharedList.length = 0; for (var i = 0; i < urlList.length; ++i) { var res = getResWithUrl(urlList[i]); @@ -273,8 +269,6 @@ proto.flowInDeps = function (owner, urlList, callback) { var item = this.getItem(res.url); if (item) { _sharedList.push(item); - // Collect deps to avoid circle reference - owner && owner.deps.push(item); } else { _sharedList.push(res); @@ -289,7 +283,7 @@ proto.flowInDeps = function (owner, urlList, callback) { callback(errors, items); // Clear deps because it's already done // Each item will only flowInDeps once, so it's still safe here - owner && (owner.deps.length = 0); + owner && owner.deps && (owner.deps.length = 0); items.destroy(); }); if (owner) { diff --git a/cocos2d/core/load-pipeline/loading-items.js b/cocos2d/core/load-pipeline/loading-items.js index b0977ba5d8..baee6ca746 100644 --- a/cocos2d/core/load-pipeline/loading-items.js +++ b/cocos2d/core/load-pipeline/loading-items.js @@ -413,7 +413,7 @@ LoadingItems.initQueueDeps = function (queue) { } }; -LoadingItems.registerDep = function (owner, depId) { +LoadingItems.registerQueueDep = function (owner, depId) { var queueId = owner.queueId || owner; if (!queueId) { return false; @@ -463,6 +463,9 @@ proto.append = function (urlList, owner) { if (!this.active) { return []; } + if (owner && !owner.deps) { + owner.deps = []; + } this._appending = true; var accepted = [], i, url, item; @@ -472,6 +475,8 @@ proto.append = function (urlList, owner) { // Already queued in another items queue, url is actually the item if (url.queueId && !this.map[url.id]) { this.map[url.id] = url; + // Register item deps for circle reference check + owner && owner.deps.push(url); // Queued and completed or Owner circle referenced by dependency if (url.complete || checkCircleReference(owner, url)) { this.totalCount++; @@ -485,7 +490,7 @@ proto.append = function (urlList, owner) { var queue = _queues[url.queueId]; if (queue) { this.totalCount++; - LoadingItems.registerDep(owner || this._id, url.id); + LoadingItems.registerQueueDep(owner || this._id, url.id); // console.log('+++++ Waited ' + url.id); queue.addListener(url.id, function (item) { // console.log('----- Completed by waiting ' + item.id + ', rest: ' + (self.totalCount - self.completedCount-1)); @@ -503,7 +508,9 @@ proto.append = function (urlList, owner) { if (!this.map[key]) { this.map[key] = item; this.totalCount++; - LoadingItems.registerDep(owner || this._id, key); + // Register item deps for circle reference check + owner && owner.deps.push(item); + LoadingItems.registerQueueDep(owner || this._id, key); accepted.push(item); // console.log('+++++ Appended ' + item.id); }