ruffle-rs / ruffle

A Flash Player emulator written in Rust
https://ruffle.rs
Other
15.17k stars 781 forks source link

ruffle executes wrong frame scripts on movieclips with dynamically added children #14629

Open nivkner opened 6 months ago

nivkner commented 6 months ago

Describe the bug

it seems like when adding a child with its own children via addChild while in a frame, as opposed to it being part of the frame, the frame scripts of the grandchildren can execute before the child finished its construction.

i made an SWF (attached below) based on the button_nested_frame_simple test which demonstrates this behavior.

when running the SWF with ruffle with the command line:

RUST_LOG=warn,ruffle_core=debug,avm_trace=trace ./ruffle_desktop -g gl test.swf

i get the following output:

2024-01-06T00:27:30.436544Z  WARN egui_wgpu::renderer: Detected a linear (sRGBA aware) framebuffer Rgba8UnormSrgb. egui prefers Rgba8Unorm or Bgra8Unorm    
2024-01-06T00:27:30.481086Z  INFO ruffle_core::library: Loaded new device font "Noto Sans" from swf tag
2024-01-06T00:27:30.495783Z  INFO ruffle_core::player: Loaded SWF version 16, resolution 550x400 @ 24 FPS
2024-01-06T00:27:30.647856Z  INFO run_frame:run_all_phases_avm2: avm_trace: Main Constructor
2024-01-06T00:27:30.647967Z  INFO run_frame:run_all_phases_avm2: avm_trace: Main addFrameScript
2024-01-06T00:27:30.647991Z  INFO run_frame:run_all_phases_avm2: avm_trace: Main frame1
2024-01-06T00:27:30.650296Z  INFO run_frame:run_all_phases_avm2: avm_trace: Main frame2
2024-01-06T00:27:30.650380Z  INFO run_frame:run_all_phases_avm2: avm_trace: MyContainer Constructor
2024-01-06T00:27:30.650403Z  INFO run_frame:run_all_phases_avm2: avm_trace: MyChild Constructor
2024-01-06T00:27:30.650416Z  INFO run_frame:run_all_phases_avm2: avm_trace: MyChild addFrameScript
2024-01-06T00:27:30.650430Z  INFO run_frame:run_all_phases_avm2: avm_trace: MyChild Constructor
2024-01-06T00:27:30.650442Z  INFO run_frame:run_all_phases_avm2: avm_trace: MyChild addFrameScript
2024-01-06T00:27:30.650622Z  INFO run_frame:run_all_phases_avm2: avm_trace: MyContainer addFrameScript
2024-01-06T00:27:30.650649Z  INFO run_frame:run_all_phases_avm2: avm_trace: MyContainer frame1
2024-01-06T00:27:30.650657Z  INFO run_frame:run_all_phases_avm2: avm_trace: MyChild frame1
2024-01-06T00:27:30.650663Z  INFO run_frame:run_all_phases_avm2: avm_trace: MyChild frame1
2024-01-06T00:27:30.671357Z  INFO run_frame:run_all_phases_avm2: avm_trace: MyChild frame2
2024-01-06T00:27:30.671384Z  INFO run_frame:run_all_phases_avm2: avm_trace: MyChild frame2

Expected behavior

expected to get the same output as the flash player.

when running the same SWF with flash player (debug version), the contents of the log are:

Main Constructor
Main addFrameScript
Main frame1
Main frame2
MyContainer Constructor
MyChild Constructor
MyChild addFrameScript
MyChild Constructor
MyChild addFrameScript
MyChild frame1
MyChild frame1
MyContainer addFrameScript
MyChild frame2
MyChild frame2

Content Location

here is the zip containing the SWF as test.swf, along with the scripts and fla file.

test.zip

Affected platform

Desktop app

Operating system

Fedora Linux 39.20240104.0 (Silverblue)

Browser

No response

Additional information

tested on:

ruffle 0a6a95e6f1bb9becd6dc97e590a06f90a75c083c
rustc 1.77.0-nightly (f688dd684 2024-01-04)
Lord-McSweeney commented 6 months ago

@Aaron1011 is this a known issue?

Aaron1011 commented 6 months ago

Yes - I thought I had opened an issue for it, but I guess not

nivkner commented 6 months ago

is it a duplicate of #12443? i just noticed it

n0samu commented 6 months ago

Was about to ask the same

Aaron1011 commented 6 months ago

Buttons are particularly awful, but there's also a more general issue with changes to displaylists in the middle of framescript execution. I think we might need a separate passes that queues framscripts for execution in a single list