Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/webgal/src/Core/gameScripts/playVideo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ export const playVideo = (sentence: ISentence): IPerform => {
if (VocalControl !== null) {
VocalControl.currentTime = 0;
VocalControl.volume = bgmVol;
// 双击可跳过视频
WebGAL.events.fullscreenDbClick.on(skipVideo);
/**
* 把bgm和语音的音量设为0
*/
Expand All @@ -78,6 +76,9 @@ export const playVideo = (sentence: ISentence): IPerform => {
}

VocalControl?.play().catch(() => {});
if (!blockingNextFlag) {
WebGAL.events.fullscreenDbClick.on(skipVideo);
}
Comment on lines +79 to +81

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

由于 playVideo 中的初始化逻辑是在 setTimeout(..., 1) 中异步执行的,如果视频在播放开始后的极短时间内(例如 1ms 内)被卸载或跳过,restoreVolumeAndUnmount 会先被调用。此时,setTimeout 回调仍会执行,并注册全局双击事件监听器 WebGAL.events.fullscreenDbClick.on(skipVideo)。这会导致内存泄漏,并且在后续双击时可能会触发已销毁实例的 endPerform,引发非预期错误。

建议在注册事件监听器前,先检查 VocalControl 是否仍存在于 DOM 树中(即未被卸载)。

Suggested change
if (!blockingNextFlag) {
WebGAL.events.fullscreenDbClick.on(skipVideo);
}
if (!blockingNextFlag && document.contains(VocalControl)) {
WebGAL.events.fullscreenDbClick.on(skipVideo);
}


VocalControl.onended = () => {
endPerform();
Expand Down
Loading