3.8.4下promise和resolve崩溃的问题

3.8.3下裂代码可以顺利执行
await Promise.all([
this.moveTail(tailLeft, targetLeftPos, true),
this.moveTail(tailRight, targetRightPos, false)
]);

           ....
              private async moveTail(tailNode: Node, targetPosition: Vec3, isLeft:boolean): Promise<void> {
    let motionStreakCompTailing = tailNode.getChildByName("tailing").getComponent(MotionStreak);
    let motionStreakCompTailingCenter = tailNode.getChildByName("tailing_center").getComponent(MotionStreak);

    motionStreakCompTailing.stroke *= 4;
    motionStreakCompTailingCenter.stroke *= 4;

    const initialStrokeTailing = motionStreakCompTailing.stroke;
    const initialStrokeTailingCenter = motionStreakCompTailingCenter.stroke;

    return new Promise(resolve => {
        // 使用 Utils.jumpTo_v3 来计算跳跃过程中的最高点位置
        const jumpHeight = Utils.calculateAdjustedJumpHeight(tailNode.position, true);
        const peakPosition = Utils.jumpTo_v3(targetPosition, jumpHeight); // 假设 Utils.jumpTo_v3 是计算跳跃轨迹的函数
        setTimeout(() => {
            ...
        }, 420);
        tween(tailNode)
            .to(0.55, { position: peakPosition, scale: new Vec3(0.05, 0.05, 0.05) }, {
                easing: easing.quadInOut,
                onUpdate: (target, ratio) => {
                    // 动态调整 Stroke 宽度
                    motionStreakCompTailing.stroke = initialStrokeTailing * (1 - ratio * 0.9); // 结束时为0.3倍
                    motionStreakCompTailingCenter.stroke = initialStrokeTailingCenter * (1 - ratio * 0.9); // 结束时为0.3倍
                }
            })
            .call(() => {
                resolve(); // *这里崩溃*
            })
            .then(tween()
                .to(0.3, { opacity: 0 }) // 这里假设tailNode或其子节点有适用的组件来调整透明度
                .call(() => {
                    tailNode.removeFromParent(); // 完成淡出后从父节点中移除
                    tailNode.destroy(); // 完成淡出后销毁节点
                }))
            .start();
    });
}
           ....

请问是什么原因导致resolve(); // 这里崩溃
我看了3.8.4 更新内容只有一个牵涉到promise——“ * 修复原生平台上调用 game.restart() 的时候如果有 promise 异常未处理而导致的崩溃问题”

但是我测试是在h5上报错

H5 ?崩溃?浏览器预览的时候浏览器进程崩了?

报错如下:

utputTypeError: Cannot read properties of null (reading ‘length’)
at TweenAction.update (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:71735:44)
at Sequence.update (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:261471:23)
at Sequence.update (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:261471:23)
at Sequence.step (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:261282:16)
at ActionManager.update (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:262512:45)
at TweenSystem.update (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:71852:28)
at Director.tick (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:16673:34)
at Game._updateCallback (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:17701:22)
at Pacer.updateCallback [as _callback] (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:91108:22)
at Pacer._handleRAF (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:91088:23)
index.js:71735
outputTypeError: Cannot read properties of null (reading ‘length’)
at TweenAction.update (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:71735:44)
at Sequence.update (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:261471:23)
at Sequence.update (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:261471:23)
at Sequence.step (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:261282:16)
at ActionManager.update (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:262512:45)
at TweenSystem.update (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:71852:28)
at Director.tick (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:16673:34)
at Game._updateCallback (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:17701:22)
at Pacer.updateCallback [as _callback] (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:91108:22)
at Pacer._handleRAF (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:91088:23)
index.js:71735
outputTypeError: Cannot read properties of null (reading ‘length’)
at TweenAction.update (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:71735:44)
at Sequence.update (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:261471:23)
at Sequence.update (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:261471:23)
at Sequence.step (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:261282:16)
at ActionManager.update (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:262512:45)

感谢反馈。
把 resolve() 放到一个 setTimeout 延时一下执行呢?
方便整理出一个复现问题的 Demo 吗?我这里排查看看。

测试了,还是会报错到这一步
.call(() => {
setTimeout(() => {
resolve(); // 动画完成后立即解析Promise
}, 1);
})
demo不太方便,因为是一个动画展示,我需要在tween序列中间调用resolve(进行下面的展示),原来3.8.3是可以的
tween(tailNode)
.to(0.55, { position: peakPosition, scale: new Vec3(0.05, 0.05, 0.05) }, {
easing: easing.quadInOut,
onUpdate: (target, ratio) => {

                }
            })
            .call(() => {
                resolve(); // 动画完成后立即解析Promise
            })
            .then(tween() // 开始新的tween序列处理淡出和销毁
               
                .to(0.3, { opacity: 0 }) // 这里假设tailNode或其子节点有适用的组件来调整透明度
                .call(() => {
                    tailNode.removeFromParent(); // 完成淡出后从父节点中移除
                    tailNode.destroy(); // 完成淡出后销毁节点
                }))
            .start();

测试下,如果不调用移除和销毁节点是否也会出现?

应该不是promise的锅,大概率是节点销毁了,resolve回调里还在引用。另外调用destroy前不用removeFromParent吧,多此一举了呀

1赞

注释了这两个还是会报错
tween(tailNode)
.to(0.55, { position: peakPosition, scale: new Vec3(0.05, 0.05, 0.05) }, {
easing: easing.quadInOut,
onUpdate: (target, ratio) => {
// 动态调整 Stroke 宽度
motionStreakCompTailing.stroke = initialStrokeTailing * (1 - ratio * 0.9); // 结束时为0.3倍
motionStreakCompTailingCenter.stroke = initialStrokeTailingCenter * (1 - ratio * 0.9); // 结束时为0.3倍
}
})
.call(() => {
resolve(); // 动画完成后立即解析Promise
})
.then(tween() // 开始新的tween序列处理淡出和销毁
.to(0.3, { opacity: 0 }) // 这里假设tailNode或其子节点有适用的组件来调整透明度
.call(() => {
// tailNode.removeFromParent(); // 完成淡出后从父节点中移除
// tailNode.destroy(); // 完成淡出后销毁节点
}))
.start();