Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix onProgress will be invoked even onComplete has been called #7121

Merged
merged 5 commits into from Aug 20, 2020

Conversation

holycanvas
Copy link
Contributor

@holycanvas holycanvas commented Aug 12, 2020

@@ -111,7 +114,7 @@ var loadOneAssetPipeline = new Pipeline('loadOneAsset', [
}
}
item.content = asset;
task.dispatch('progress', ++progress.finish, progress.total, item);
progress.shouldInvoke && task.dispatch('progress', ++progress.finish, progress.total, item);
Copy link
Member

@jareguo jareguo Aug 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看起来不像是 shouldInvoke,更像是 canInvoke

@@ -49,7 +49,10 @@ function load (task, done) {
options,
progress,
onComplete: function (err, item) {
if (err && !task.isFinish && !cc.assetManager.force) done(err);
if (err && !task.isFinish && !cc.assetManager.force) {
progress.shouldInvoke = false;
Copy link
Member

@jareguo jareguo Aug 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里直接把监听的 progress 变为 null 不行吗?

Copy link
Member

@jareguo jareguo Aug 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果不再调用 progress 的话,需要确保 progress 最后一次调用一定会 === 100%,特别是没有 complete 回调的时候

Copy link
Contributor Author

@holycanvas holycanvas Aug 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

特别是没有 complete 回调的时候

没有这个情况吧

这里直接把监听的 progress 变为 null 不行吗?

在资源加载的过程中,一个任务可能会生成很多子任务(用于加载依赖资源),所有任务之间是复用了同一个 progress 对象,没法去改所有子任务的 progress 为 null,这个很麻烦(这里是一个任务树),只能在共享的 progress 加一个字段来作为标志

Copy link
Member

@jareguo jareguo Aug 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一样啊,那如果 complete 了,其它任务也无法触发 progress 了,跟置空没太大区别。

Copy link
Member

@jareguo jareguo Aug 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有这个情况吧

万一玩家没传入加载后的回调(例如切换场景之类的),确实通过进度值也应该能判断出加载是否结束,需要确保进度值会到达 100%

Copy link
Contributor Author

@holycanvas holycanvas Aug 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

万一玩家没传入加载后的回调(例如切换场景之类的),确实通过进度值也应该能判断出加载是否结束

他既然要判断是否加载结束,就应该传 complete 回调啊。如果加载进度到10% 就发生错误报错了,我们直接跳到100%,感觉这样才比较奇怪

Copy link
Contributor Author

@holycanvas holycanvas Aug 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一样啊,那如果 complete 了,其它任务也无法触发 progress 了,跟置空没太大区别。

加载过程中,任务是递归生成的,不是一次全生成。会一层一层的往下生成子任务,progress 会作为一个参数传给子任务。全部任务都在并行加载。如果发生错误,我们把progress置空,那么只会影响这一刻之后新建的任务不会执行进度回调。而之前已经创建好的正在加载的任务,progress 已经赋值进去了,不会受到影响,除非我们遍历整个任务树,挨个重置 progress。这样就会麻烦,还得记录所有的子任务,

@holycanvas holycanvas merged commit 2870fab into cocos:v2.4.3-release Aug 20, 2020
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants