-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Android原生版本, cocos的API game.restart()
返回值为 undefined .
#17924
Comments
This comment was marked as resolved.
This comment was marked as resolved.
在原生平台,因为整个虚拟机重启了,所以没法执行 promise。按照我上面的修改没有效果。 |
@minggo 其实只要能重启游戏, 这个函数的使命就完成了. 目前cocos中执行下面的代码 原生平台会报错: cc.game.restart().then(()=>{
console.log('game restart')
}) d.ts 里也没有说 cc.game.restart() 可能返回 undefined. 两个修改思路:
cc.game.restart = function () {
CC_LOG_WARNING('在此处告诉开发者 原生平台后面的 promise 不会被执行')
// Need to clear scene, or native object destructor won't be invoke.
cc.director.getScene().destroy();
cc.Object._deferredDestroy();
__restartVM();
return Promise.resolve();
}; 我个人更喜欢 方案2 这样 在ts代码里 执行 cc.game.restart().then(()=>{
console.log('game restart')
}) 至少不会报错. 虽然 否则我还要自己去判断 |
现在对外导出的 web 的 api。你说的报错是啥意思? |
@minggo
报错啊. 因为原生平台 cc.game.restart() 返回值是 undefined. 类似
这样的错误 |
我试试。原生的话,restart 已经重启了虚拟机,then 的代码应该都不会执行了。你是哪个平台测试的? |
我在 mac 测试的,没看到报错。 |
taptap 安卓 apk |
Cocos Creator version
3.8.4
System information
android
Issue description
从cocos源码里来看, 应该返回一个 Promise 对象, 小游戏和web版本来看, 也确实是 Promise .
但是 Android原生版本 返回 undefined .
原生在 jsb-game.js 里被替换成了
此处应该保证 返回值 与 web/小游戏 平台一致, 哪怕返回一个空的/虚假的 Promise对象 也好.
Relevant error log output
No response
Steps to reproduce
.
Minimal reproduction project
No response
The text was updated successfully, but these errors were encountered: