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 small issues #6688

Merged
merged 14 commits into from May 21, 2020
Merged

fix small issues #6688

merged 14 commits into from May 21, 2020

Conversation

holycanvas
Copy link
Contributor

@holycanvas holycanvas commented May 14, 2020

Re: cocos-creator/2d-tasks#

Changes:

  • 移除释放检查错误的算法
  • 完善代码可读性
  • 避免重复释放已释放的资源
  • 修复 vscode 中识别 d.ts 错误的问题(vscode 遇到注释中的 [] 会直接卡住)
  • 修复没有延迟加载的问题
  • 修复场景预加载后,正常加载卡住的问题
  • 修复 imageBitmap 在 firefox 上不支持 options 的问题
  • fix typo
  • 修复 loadBundle 失败时执行两次回调的问题
  • 修复 onLoad 中设置节点的 size,在 onEnable 中被重置回来的问题

@@ -199,24 +199,6 @@ var releaseManager = {
_toDelete.remove(asset._uuid);

if (!force) {

if (!CC_NATIVERENDERER) {
Copy link
Contributor Author

@holycanvas holycanvas May 15, 2020

Choose a reason for hiding this comment

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

这个判断不对,_current.textureUnits 压根就不是本帧所有贴图,只是最后一个 drawcall 的贴图,没有地方能统计到本帧的,所以还是不判断了

}
else {
cb.onComplete(null, data);
}
Copy link
Contributor Author

@holycanvas holycanvas May 15, 2020

Choose a reason for hiding this comment

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

提高下可读性,全是大括号太烦

@jareguo
Copy link
Member

jareguo commented May 16, 2020

难道不是 removeBundle 就能自动释放吗?(引用计数)

@holycanvas
Copy link
Contributor Author

holycanvas commented May 18, 2020

难道不是 removeBundle 就能自动释放吗?(引用计数)

现在 bundle 是没有引用资源的,所以也没办法在 removeBundle 的时候去减引用

@@ -416,8 +416,8 @@ AssetManager.prototype = {
* Every custom parameter in `requests` will be tranfered to handler of `downloader` and `parser` as `options`.
* You can register you own handler downloader or parser to collect these custom parameters for some effect.
*
* Reserved Keyword: [`uuid`, `url`, `path`, `dir`, `scene`, `type`, `priority`, `preset`, `audioLoadMode`, `ext`, `bundle`, `onFileProgress`, `maxConcurrency`, `maxRequestsPerFrame`
Copy link
Contributor Author

@holycanvas holycanvas May 18, 2020

Choose a reason for hiding this comment

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

vs code 不识别中括号。。。

}
}
}
if (!cc.isValid(asset, true)) return;
Copy link
Contributor Author

@holycanvas holycanvas May 21, 2020

Choose a reason for hiding this comment

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

如果资源已经释放过了,不应该再释放一次

@@ -173,6 +175,7 @@ var dependUtil = {
// get deps from an existing asset
else {
var asset = json;
out = {};
Copy link
Member

@jareguo jareguo May 21, 2020

Choose a reason for hiding this comment

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

out = { deps: [], preventPreloadNativeObject: xxx, preventDeferredLoadDependents: xxx };

Copy link
Contributor Author

@holycanvas holycanvas May 21, 2020

Choose a reason for hiding this comment

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

已改

@holycanvas holycanvas changed the title export releaseUnusedAssets fix small issues May 21, 2020
@@ -415,9 +415,14 @@ var Sprite = cc.Class({
*/
getState () {},

onEnable () {
__preload () {
this._super();
this._applySpriteFrame();
Copy link
Contributor Author

@holycanvas holycanvas May 21, 2020

Choose a reason for hiding this comment

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

把 _applySpriteFrame 从 onEnable 提到 __preload 中


onEnable () {
this._super();
this._spriteFrame && this._spriteFrame.ensureLoadTexture();
Copy link
Contributor Author

@holycanvas holycanvas May 21, 2020

Choose a reason for hiding this comment

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

onEnable 中只用确保图片被加载即可

this._applySpriteSize();
}
else {
this.disableRender();
spriteFrame.onTextureLoaded(this._applySpriteSize, this);
spriteFrame.once('load', this._applySpriteSize, this);
Copy link
Contributor Author

@holycanvas holycanvas May 21, 2020

Choose a reason for hiding this comment

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

监听回调即可

};

if (typeof createImageBitmap !== 'undefined' && typeof Blob !== 'undefined') {
_tmpCanvas1.width = _tmpCanvas1.height = 2;
Copy link
Contributor Author

@holycanvas holycanvas May 21, 2020

Choose a reason for hiding this comment

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

imageBitmap 在某些浏览器上,可能不支持 option 参数,所以得实际调用一次来判断是否真的支持

@@ -465,7 +465,7 @@ cc.js.mixin(View.prototype, {
if(cc.game.renderType === cc.game.RENDER_TYPE_WEBGL) {
var cache = cc.assetManager.assets;
cache.forEach(function (asset) {
if (asset instanceof cc.Texture2Dx) {
if (asset instanceof cc.Texture2D) {
Copy link
Contributor Author

@holycanvas holycanvas May 21, 2020

Choose a reason for hiding this comment

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

typo

}
out = response;
count++;
if (count === 2) {
onComplete(null, out);
Copy link
Contributor Author

@holycanvas holycanvas May 21, 2020

Choose a reason for hiding this comment

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

执行一次回调就行

@@ -415,9 +415,14 @@ var Sprite = cc.Class({
*/
getState () {},

onEnable () {
__preload () {
this._super();
Copy link
Member

@jareguo jareguo May 21, 2020

Choose a reason for hiding this comment

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

image

好像本来就有定义 preload 了

@holycanvas holycanvas merged commit 53e95ea into cocos:v2.4.0 May 21, 2020
1 check passed

if (typeof createImageBitmap !== 'undefined' && typeof Blob !== 'undefined') {
_tmpCanvas1.width = _tmpCanvas1.height = 2;
createImageBitmap(_tmpCanvas1, {}).then(imageBitmap => {
Copy link
Contributor

@dumganhar dumganhar Jul 3, 2020

Choose a reason for hiding this comment

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

为什么要使用 ImageBitmap ?
HTMLImageElement 不香么?

Copy link
Contributor Author

@holycanvas holycanvas Jul 3, 2020

Choose a reason for hiding this comment

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

HTMLImageElement 在上传GPU的时候,浏览器会执行一个 decode 的操作,这个操作需要时的时间跟图像的分辨率大小成正比,而且有个严重的问题是,这个操作是同步的,所以如果图片很多的时候,会非常卡顿,而且因为是同步的,所以图片只能一张接着一张的decode,所以会很慢。而 imageBitmap 在浏览器上是在多线程中解码的,所以可以并行,会更快,而且因为少了同步的操作,卡顿也会变少。不想使用的话,可以用 cc.macro.ALLOW_IMAGE_BITMAP 来关闭使用

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

3 participants