Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avm2: Initialize the loaderURL for empty movies #17717

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/src/avm2/globals/flash/display/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn loader_allocator<'gc>(
// us the correct value (0) for them.
let loader_info = LoaderInfoObject::not_yet_loaded(
activation,
Arc::new(SwfMovie::empty(activation.context.swf.version())),
Arc::new(SwfMovie::empty_child(activation.context.swf)),
Some(loader),
None,
false,
Expand Down Expand Up @@ -93,7 +93,7 @@ pub fn load<'gc>(

// This is a dummy MovieClip, which will get overwritten in `Loader`
let content = MovieClip::new(
Arc::new(SwfMovie::empty(activation.context.swf.version())),
Arc::new(SwfMovie::empty_child(activation.context.swf)),
activation.context.gc_context,
);

Expand All @@ -103,7 +103,7 @@ pub fn load<'gc>(
.unwrap()
.set_loader_stream(
LoaderStream::NotYetLoaded(
Arc::new(SwfMovie::empty(activation.context.swf.version())),
Arc::new(SwfMovie::empty_child(activation.context.swf)),
Some(content.into()),
false,
),
Expand Down Expand Up @@ -256,7 +256,7 @@ pub fn load_bytes<'gc>(

// This is a dummy MovieClip, which will get overwritten in `Loader`
let content = MovieClip::new(
Arc::new(SwfMovie::empty(activation.context.swf.version())),
Arc::new(SwfMovie::empty_child(activation.context.swf)),
activation.context.gc_context,
);

Expand Down
2 changes: 1 addition & 1 deletion core/src/avm2/object/loaderinfo_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ impl<'gc> LoaderInfoObject<'gc> {

pub fn unload(&self, activation: &mut Activation<'_, 'gc>) {
// Reset properties
let empty_swf = Arc::new(SwfMovie::empty(activation.context.swf.version()));
let empty_swf = Arc::new(SwfMovie::empty_child(activation.context.swf));
let loader_stream = LoaderStream::NotYetLoaded(empty_swf, None, false);
self.set_loader_stream(loader_stream, activation.context.gc_context);
self.set_errored(false);
Expand Down
5 changes: 2 additions & 3 deletions core/src/display_object/movie_clip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ impl<'gc> MovieClip<'gc> {
loader_info: Option<LoaderInfoObject<'gc>>,
) {
let mut mc = self.0.write(context.gc_context);
let movie = movie.unwrap_or_else(|| Arc::new(SwfMovie::empty(mc.movie().version())));
let movie = movie.unwrap_or_else(|| Arc::new(SwfMovie::empty_child(&mc.movie())));
let total_frames = movie.num_frames();
assert_eq!(
mc.static_data.loader_info, None,
Expand Down Expand Up @@ -2478,9 +2478,8 @@ impl<'gc> MovieClip<'gc> {
fn transform_to_unloaded_state(&self, context: &mut UpdateContext<'gc>) {
let movie = if let Some(DisplayObject::MovieClip(parent_mc)) = self.parent() {
let parent_movie = parent_mc.movie();
let parent_version = parent_movie.version();
let parent_url = parent_movie.url();
let mut unloaded_movie = SwfMovie::empty(parent_version);
let mut unloaded_movie = SwfMovie::empty_child(&parent_movie);
unloaded_movie.set_url(parent_url.to_string());

Some(Arc::new(unloaded_movie))
Expand Down
3 changes: 1 addition & 2 deletions core/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2689,9 +2689,8 @@ impl<'gc> Loader<'gc> {
// In this loading state, the URL is the URL of the parent movie / doesn't change.

let current_movie = mc.movie();
let current_version = current_movie.version();
let current_url = current_movie.url();
let mut initial_loading_movie = SwfMovie::empty(current_version);
let mut initial_loading_movie = SwfMovie::empty_child(&current_movie);
initial_loading_movie.set_url(current_url.to_string());

mc.replace_with_movie(uc, Some(Arc::new(initial_loading_movie)), true, None);
Expand Down
14 changes: 14 additions & 0 deletions core/src/tag_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ impl SwfMovie {
}
}

/// Construct an empty child movie.
pub fn empty_child(parent: &SwfMovie) -> Self {
Self {
header: HeaderExt::default_with_swf_version(parent.version()),
data: vec![],
url: "file:///".into(),
loader_url: Some(parent.url().into()),
parameters: Vec::new(),
encoding: swf::UTF_8,
compressed_len: 0,
is_movie: false,
}
}

/// Construct an empty movie with a fake `compressed_len`.
/// This is used by `Loader` when firing an initial `progress` event:
/// `LoaderInfo.bytesTotal` is set to the actual value, but no data is available,
Expand Down