avm1: Fix GotoFrame2 one-frame-off error

Frame numbers pushed/popped from the stack for GotoFrame2 are
1-based. This differs for GotoFrame which is 0-based and encodes
the frame alongside the instruction.
This commit is contained in:
Mike Welsh 2019-09-27 18:09:52 -07:00
parent 1c88de5132
commit c8cec3132f
2 changed files with 5 additions and 1 deletions

View File

@ -738,6 +738,7 @@ impl<'gc> Avm1<'gc> {
if let Some(clip) = context.target_clip { if let Some(clip) = context.target_clip {
let mut display_object = clip.write(context.gc_context); let mut display_object = clip.write(context.gc_context);
if let Some(clip) = display_object.as_movie_clip_mut() { if let Some(clip) = display_object.as_movie_clip_mut() {
// The frame on the stack is 0-based, not 1-based.
clip.goto_frame(frame + 1, true); clip.goto_frame(frame + 1, true);
} else { } else {
log::error!("GotoFrame failed: Target is not a MovieClip"); log::error!("GotoFrame failed: Target is not a MovieClip");
@ -761,7 +762,8 @@ impl<'gc> Avm1<'gc> {
if let Some(clip) = display_object.as_movie_clip_mut() { if let Some(clip) = display_object.as_movie_clip_mut() {
match self.pop()? { match self.pop()? {
Value::Number(frame) => { Value::Number(frame) => {
clip.goto_frame(scene_offset + (frame as u16) + 1, !set_playing) // The frame on the stack is 1-based, not 0-based.
clip.goto_frame(scene_offset + (frame as u16), !set_playing)
} }
Value::String(frame_label) => { Value::String(frame_label) => {
if let Some(frame) = clip.frame_label_to_number(&frame_label) { if let Some(frame) = clip.frame_label_to_number(&frame_label) {

View File

@ -104,6 +104,8 @@ impl<'gc> MovieClip<'gc> {
self.is_playing = false; self.is_playing = false;
} }
/// Queues up a goto to the specified frame.
/// `frame` should be 1-based.
pub fn goto_frame(&mut self, frame: FrameNumber, stop: bool) { pub fn goto_frame(&mut self, frame: FrameNumber, stop: bool) {
if frame != self.current_frame { if frame != self.current_frame {
self.goto_queue.push(frame); self.goto_queue.push(frame);