diff --git a/core/src/display_object/container.rs b/core/src/display_object/container.rs index 7c152937ef8b..03b58c950235 100644 --- a/core/src/display_object/container.rs +++ b/core/src/display_object/container.rs @@ -381,15 +381,18 @@ pub trait TDisplayObjectContainer<'gc>: /// Insert a child directly into this container's depth list. fn insert_child_into_depth_list( &mut self, - gc_context: &Mutation<'gc>, + context: &mut UpdateContext<'_, 'gc>, depth: Depth, child: DisplayObject<'gc>, ) { - self.raw_container_mut(gc_context) + let this: DisplayObject<'_> = (*self).into(); + + child.set_depth(context.gc_context, depth); + child.set_parent(context, Some(this)); + self.raw_container_mut(context.gc_context) .insert_child_into_depth_list(depth, child); - let this: DisplayObject<'_> = (*self).into(); - this.invalidate_cached_bitmap(gc_context); + this.invalidate_cached_bitmap(context.gc_context); } /// Removes (without unloading) a child display object from this container's depth list. diff --git a/core/src/loader.rs b/core/src/loader.rs index da79051d692d..6dab6934fac7 100644 --- a/core/src/loader.rs +++ b/core/src/loader.rs @@ -42,6 +42,9 @@ use url::{form_urlencoded, ParseError, Url}; pub type Handle = Index; +/// The depth of AVM1 movies that AVM2 loads. +const LOADER_INSERTED_AVM1_DEPTH: i32 = -0xF000; + /// How Ruffle should load movies. #[cfg_attr(feature = "clap", derive(clap::ValueEnum))] #[derive(Debug, Clone, Copy, PartialEq)] @@ -1730,6 +1733,8 @@ impl<'gc> Loader<'gc> { { // When an AVM2 movie loads an AVM1 movie, we need to call `post_instantiation` here. mc.post_instantiation(uc, None, Instantiator::Movie, false); + + mc.set_depth(uc.gc_context, LOADER_INSERTED_AVM1_DEPTH); } } @@ -2007,8 +2012,8 @@ impl<'gc> Loader<'gc> { if !movie.unwrap().is_action_script_3() { loader.insert_child_into_depth_list( - activation.context.gc_context, - 0, + &mut activation.context, + LOADER_INSERTED_AVM1_DEPTH, dobj.unwrap(), ); } diff --git a/tests/tests/swfs/avm2/mixed_avm/avm1.swf b/tests/tests/swfs/avm2/mixed_avm/avm1.swf index 373d6d365b1c..ca42f8796d1f 100644 Binary files a/tests/tests/swfs/avm2/mixed_avm/avm1.swf and b/tests/tests/swfs/avm2/mixed_avm/avm1.swf differ diff --git a/tests/tests/swfs/avm2/mixed_avm/output.txt b/tests/tests/swfs/avm2/mixed_avm/output.txt index 0228487f4849..ba7a662a2542 100644 --- a/tests/tests/swfs/avm2/mixed_avm/output.txt +++ b/tests/tests/swfs/avm2/mixed_avm/output.txt @@ -1,5 +1,11 @@ Starting load... +_global access in DoInitAction: +[type Object] +root depth: +-77824 hello from avm1! +Root depth: -77824 +_root == _level0: false [object AVM1Movie] [object ApplicationDomain] Load complete!