From 4a7e69337fd9df7dc14d1510f9baa6c50306d4e5 Mon Sep 17 00:00:00 2001 From: YeomaiPC Date: Sat, 12 Sep 2026 00:03:31 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MAC_arm64_SpineViewer/viewer/spine.html | 33 ++++++++++++++----- .../UNIVERSAL_SpineViewer/viewer/spine.html | 33 ++++++++++++++----- release/WIN_x64_SpineViewer/viewer/spine.html | 33 ++++++++++++++----- viewer/spine.html | 33 ++++++++++++++----- 4 files changed, 100 insertions(+), 32 deletions(-) diff --git a/release/MAC_arm64_SpineViewer/viewer/spine.html b/release/MAC_arm64_SpineViewer/viewer/spine.html index 95c44d5..e74d254 100644 --- a/release/MAC_arm64_SpineViewer/viewer/spine.html +++ b/release/MAC_arm64_SpineViewer/viewer/spine.html @@ -707,7 +707,7 @@ } updateWorld(skeleton); draw(); - const entry = state.getCurrent(0); + const entry = currentTrack(); if (entry) { const currentTime = getTrackAnimationTime(entry); if (now >= statusHoldUntil) { @@ -966,10 +966,23 @@ } } + // Spine 4.3 起 AnimationState.getCurrent() 被改名为 getTrack(),这里统一做版本兼容。 + function currentTrack() { + if (!state) return null; + try { + if (typeof state.getCurrent === 'function') return state.getCurrent(0) || null; + if (typeof state.getTrack === 'function') return state.getTrack(0) || null; + const tracks = state.tracks; + return (tracks && tracks[0]) || null; + } catch (e) { + return null; + } + } + // 跳到指定时间点:暂停播放,重置动画到目标时间 function seekTo(time) { if (!state || !skeleton) return; - const track = state.getCurrent(0); + const track = currentTrack(); const anim = track ? track.animation : null; playing = false; updatePlayButton(); @@ -1204,7 +1217,7 @@ }); document.getElementById('loopCheck').addEventListener('change', (e) => { loop = e.target.checked; - const cur = state.getCurrent(0); + const cur = currentTrack(); if (cur) cur.loop = loop; }); document.getElementById('speedRange').addEventListener('input', (e) => { @@ -1246,11 +1259,15 @@ }); const endTimelineSeek = () => { if (!seeking) return; - seekTimelineToNearestFrame(); - seeking = false; - playing = false; - updatePlayButton(); - timeline.blur(); + try { + seekTimelineToNearestFrame(); + } finally { + // 无论吸附是否抛错都要复位,否则 seeking 会永久卡住导致时间轴不再同步。 + seeking = false; + playing = false; + updatePlayButton(); + timeline.blur(); + } }; timeline.addEventListener('pointerup', endTimelineSeek); // 指针移出滑块后松开时也要完成吸附。 diff --git a/release/UNIVERSAL_SpineViewer/viewer/spine.html b/release/UNIVERSAL_SpineViewer/viewer/spine.html index 95c44d5..e74d254 100644 --- a/release/UNIVERSAL_SpineViewer/viewer/spine.html +++ b/release/UNIVERSAL_SpineViewer/viewer/spine.html @@ -707,7 +707,7 @@ } updateWorld(skeleton); draw(); - const entry = state.getCurrent(0); + const entry = currentTrack(); if (entry) { const currentTime = getTrackAnimationTime(entry); if (now >= statusHoldUntil) { @@ -966,10 +966,23 @@ } } + // Spine 4.3 起 AnimationState.getCurrent() 被改名为 getTrack(),这里统一做版本兼容。 + function currentTrack() { + if (!state) return null; + try { + if (typeof state.getCurrent === 'function') return state.getCurrent(0) || null; + if (typeof state.getTrack === 'function') return state.getTrack(0) || null; + const tracks = state.tracks; + return (tracks && tracks[0]) || null; + } catch (e) { + return null; + } + } + // 跳到指定时间点:暂停播放,重置动画到目标时间 function seekTo(time) { if (!state || !skeleton) return; - const track = state.getCurrent(0); + const track = currentTrack(); const anim = track ? track.animation : null; playing = false; updatePlayButton(); @@ -1204,7 +1217,7 @@ }); document.getElementById('loopCheck').addEventListener('change', (e) => { loop = e.target.checked; - const cur = state.getCurrent(0); + const cur = currentTrack(); if (cur) cur.loop = loop; }); document.getElementById('speedRange').addEventListener('input', (e) => { @@ -1246,11 +1259,15 @@ }); const endTimelineSeek = () => { if (!seeking) return; - seekTimelineToNearestFrame(); - seeking = false; - playing = false; - updatePlayButton(); - timeline.blur(); + try { + seekTimelineToNearestFrame(); + } finally { + // 无论吸附是否抛错都要复位,否则 seeking 会永久卡住导致时间轴不再同步。 + seeking = false; + playing = false; + updatePlayButton(); + timeline.blur(); + } }; timeline.addEventListener('pointerup', endTimelineSeek); // 指针移出滑块后松开时也要完成吸附。 diff --git a/release/WIN_x64_SpineViewer/viewer/spine.html b/release/WIN_x64_SpineViewer/viewer/spine.html index 95c44d5..e74d254 100644 --- a/release/WIN_x64_SpineViewer/viewer/spine.html +++ b/release/WIN_x64_SpineViewer/viewer/spine.html @@ -707,7 +707,7 @@ } updateWorld(skeleton); draw(); - const entry = state.getCurrent(0); + const entry = currentTrack(); if (entry) { const currentTime = getTrackAnimationTime(entry); if (now >= statusHoldUntil) { @@ -966,10 +966,23 @@ } } + // Spine 4.3 起 AnimationState.getCurrent() 被改名为 getTrack(),这里统一做版本兼容。 + function currentTrack() { + if (!state) return null; + try { + if (typeof state.getCurrent === 'function') return state.getCurrent(0) || null; + if (typeof state.getTrack === 'function') return state.getTrack(0) || null; + const tracks = state.tracks; + return (tracks && tracks[0]) || null; + } catch (e) { + return null; + } + } + // 跳到指定时间点:暂停播放,重置动画到目标时间 function seekTo(time) { if (!state || !skeleton) return; - const track = state.getCurrent(0); + const track = currentTrack(); const anim = track ? track.animation : null; playing = false; updatePlayButton(); @@ -1204,7 +1217,7 @@ }); document.getElementById('loopCheck').addEventListener('change', (e) => { loop = e.target.checked; - const cur = state.getCurrent(0); + const cur = currentTrack(); if (cur) cur.loop = loop; }); document.getElementById('speedRange').addEventListener('input', (e) => { @@ -1246,11 +1259,15 @@ }); const endTimelineSeek = () => { if (!seeking) return; - seekTimelineToNearestFrame(); - seeking = false; - playing = false; - updatePlayButton(); - timeline.blur(); + try { + seekTimelineToNearestFrame(); + } finally { + // 无论吸附是否抛错都要复位,否则 seeking 会永久卡住导致时间轴不再同步。 + seeking = false; + playing = false; + updatePlayButton(); + timeline.blur(); + } }; timeline.addEventListener('pointerup', endTimelineSeek); // 指针移出滑块后松开时也要完成吸附。 diff --git a/viewer/spine.html b/viewer/spine.html index 95c44d5..e74d254 100644 --- a/viewer/spine.html +++ b/viewer/spine.html @@ -707,7 +707,7 @@ } updateWorld(skeleton); draw(); - const entry = state.getCurrent(0); + const entry = currentTrack(); if (entry) { const currentTime = getTrackAnimationTime(entry); if (now >= statusHoldUntil) { @@ -966,10 +966,23 @@ } } + // Spine 4.3 起 AnimationState.getCurrent() 被改名为 getTrack(),这里统一做版本兼容。 + function currentTrack() { + if (!state) return null; + try { + if (typeof state.getCurrent === 'function') return state.getCurrent(0) || null; + if (typeof state.getTrack === 'function') return state.getTrack(0) || null; + const tracks = state.tracks; + return (tracks && tracks[0]) || null; + } catch (e) { + return null; + } + } + // 跳到指定时间点:暂停播放,重置动画到目标时间 function seekTo(time) { if (!state || !skeleton) return; - const track = state.getCurrent(0); + const track = currentTrack(); const anim = track ? track.animation : null; playing = false; updatePlayButton(); @@ -1204,7 +1217,7 @@ }); document.getElementById('loopCheck').addEventListener('change', (e) => { loop = e.target.checked; - const cur = state.getCurrent(0); + const cur = currentTrack(); if (cur) cur.loop = loop; }); document.getElementById('speedRange').addEventListener('input', (e) => { @@ -1246,11 +1259,15 @@ }); const endTimelineSeek = () => { if (!seeking) return; - seekTimelineToNearestFrame(); - seeking = false; - playing = false; - updatePlayButton(); - timeline.blur(); + try { + seekTimelineToNearestFrame(); + } finally { + // 无论吸附是否抛错都要复位,否则 seeking 会永久卡住导致时间轴不再同步。 + seeking = false; + playing = false; + updatePlayButton(); + timeline.blur(); + } }; timeline.addEventListener('pointerup', endTimelineSeek); // 指针移出滑块后松开时也要完成吸附。