cocos / cocos-engine

Cocos simplifies game creation and distribution with Cocos Creator, a free, open-source, cross-platform game engine. Empowering millions of developers to create high-performance, engaging 2D/3D games and instant web entertainment.
https://www.cocos.com/en/creator
Other
8.81k stars 2.05k forks source link

Download Font [ XXX_LABEL] failed, using Arial or system default font instead #17778

Open XenonSheng opened 1 month ago

XenonSheng commented 1 month ago

Cocos Creator version

2.4.13

System information

Windows 10, Android, IOS browsers (Web Mobile)

Issue description

Sometimes might get this error "Download Font [ XXX_LABEL] failed, using Arial or system default font instead". Mostly happens on first time launch the website.

Found the solution that can solve this problem by increasing the _timeout from font_loader.js. After updated _timeout from 3s to 60s, have tested on windows 10, android, and ios devices, so far so good. Suspect that require more time to load the font.

Recommend to make the timeout variable as global variable. So we can adjust ourselves based on our needs.

Hope someone can be updated for next v2 release. Thankss

Relevant error log output

Download Font [ XXX_LABEL] failed, using Arial or system default font instead

Steps to reproduce

Get any ttf files with chinese fonts.

Minimal reproduction project

No response

longchuan commented 1 month ago

the net was timeout or the resource did not exist

XenonSheng commented 1 month ago

No network timeout. TTF files are downloaded successfully with (200 OK response). https://github.com/cocos/cocos-engine/blob/caf35a70c814561e27ebb8f372c06f6b51ee420a/cocos2d/core/asset-manager/font-loader.js#L36 Suspect it take longer time than 3 seconds. Haven't finished loaded the font, already go into the following line https://github.com/cocos/cocos-engine/blob/caf35a70c814561e27ebb8f372c06f6b51ee420a/cocos2d/core/asset-manager/font-loader.js#L109

longchuan commented 1 month ago

2.4.13 did not support the reject(Promise)

XenonSheng commented 1 month ago

我觉得 不关 reject promise 的事, 应该是可以运行的

ttf 文件 是下载成功了

可是我觉得在加载font的时候,需要更长的时间(需要大于3秒) 原因可能是华语font 比英文font 复杂

我怀疑它还没完成加载font就被强制timeout,导致font出现问题

我自己尝试了 把3秒换成 60秒, 再也没遇到这个问题

Remmoze commented 3 weeks ago

My tester has also found this bug when playing on slow internet. Even when the font is loaded it is not used properly. I would love to be able to change _timeout externally, without building the engine

longchuan commented 3 weeks ago

我觉得 不关 reject promise 的事, 应该是可以运行的

ttf 文件 是下载成功了

可是我觉得在加载font的时候,需要更长的时间(需要大于3秒) 原因可能是华语font 比英文font 复杂

我怀疑它还没完成加载font就被强制timeout,导致font出现问题

我自己尝试了 把3秒换成 60秒, 再也没遇到这个问题

加了promise也是可以运行的,但是不支持异步,会直接执行后面的代码,而异步的还在执行中,导致问题

longchuan commented 3 weeks ago

你可以尝试不使用then函数,应该会正常

XenonSheng commented 3 weeks ago

对不起 我有点不太明白您的意思。。。 因为你说的promise 只有在native 的function 用到 我在windows 一样会有font 问题, 不只是在IOS 和 ANDROID 我理解到的是 有两个function 以 useNativeCheck 来定义 用哪个

第一个是 _checkFontLoaded (用于Windows的浏览器 或者 useNativeCheck false) 这里 并没有用到任何promise。。。 而且我有尝试加入 cc.log 如图下, 确实超时了。。 image

第二个是 nativeCheckFontLoaded (用于ANDROID/IOS的浏览器 或者 useNativeCheck true ) 这里 才有用到promise 而且我有尝试加入 cc.log 如图下, 也确实超时了。。通常会进入 ’2‘ 的cc.log image

可是当我把 _timeout 换成 60秒, 就解决了。。 并没有再出现font的问题。。 image 所以我才建议,如果可以, 把这个_timeout弄成全局变量(Global Variable) 这样可以根据我们的需要进行更改。。 我们也不需要自己build engine

longchuan commented 3 weeks ago

也许是我说错了,我认为Promise.then()是不可靠的