From 0e4b0f7c62a5909e24e3298a3ab53063917eae2d Mon Sep 17 00:00:00 2001 From: Mike Welsh Date: Sun, 31 Oct 2021 12:32:27 -0700 Subject: [PATCH] avm1: Allow duplicateMovieClip on dynamically created clips Previously duplicating a clip created with `createEmptyMovieClip` would fail. --- core/src/avm1/globals/movie_clip.rs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/core/src/avm1/globals/movie_clip.rs b/core/src/avm1/globals/movie_clip.rs index 12fc70e49..a6fe9dc83 100644 --- a/core/src/avm1/globals/movie_clip.rs +++ b/core/src/avm1/globals/movie_clip.rs @@ -811,13 +811,25 @@ pub fn duplicate_movie_clip_with_bias<'gc>( return Ok(Value::Undefined); } - if let Ok(new_clip) = activation - .context - .library - .library_for_movie(movie_clip.movie().unwrap()) - .ok_or_else(|| "Movie is missing!".into()) - .and_then(|l| l.instantiate_by_id(movie_clip.id(), activation.context.gc_context)) - { + let id = movie_clip.id(); + let movie = parent + .movie() + .or_else(|| activation.base_clip().movie()) + .unwrap_or_else(|| activation.context.swf.clone()); + let new_clip = if movie_clip.id() != 0 { + // Clip from SWF; instantiate a new copy. + activation + .context + .library + .library_for_movie(movie) + .ok_or_else(|| "Movie is missing!".into()) + .and_then(|l| l.instantiate_by_id(id, activation.context.gc_context)) + } else { + // Dynamically created clip; create a new empty movie clip. + Ok(MovieClip::new(movie, activation.context.gc_context).into()) + }; + + if let Ok(new_clip) = new_clip { // Set name and attach to parent. new_clip.set_name(activation.context.gc_context, new_instance_name); parent.replace_at_depth(&mut activation.context, new_clip, depth);