Skip to content

Commit

Permalink
core: More mixed AVM fixes, improve test
Browse files Browse the repository at this point in the history
This commit breaks mixed AVM without #13889.
  • Loading branch information
Lord-McSweeney authored and Lord-McSweeney committed Dec 16, 2023
1 parent b67911b commit 30416ad
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
11 changes: 7 additions & 4 deletions core/src/display_object/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions core/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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(),
);
}
Expand Down
Binary file modified tests/tests/swfs/avm2/mixed_avm/avm1.swf
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/tests/swfs/avm2/mixed_avm/output.txt
Original file line number Diff line number Diff line change
@@ -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!
Expand Down

0 comments on commit 30416ad

Please sign in to comment.