ruffle-rs / ruffle

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

[AVM1] Sound and visual effects loop when not supposed to #3018

Open bls1999 opened 3 years ago

bls1999 commented 3 years ago

Describe the bug Within this game, when there are some sound or visual effects (namely those related to firing shots), they loop for about 5 seconds and then stop. A couple of examples are DefineSound (2: sonicBlast) and DefineSprite (77: heatSeekExplosion).

Game Link: https://jiggmin2.com/games/red-earth-2 SWF Link: https://jiggmin2.com/games/red-earth-2/red-earth-2.swf

Expected behavior A shot is fired, the corresponding explosion animation/sound effect plays once, and subsides.

Is the problem with the Ruffle desktop app, extension, or self-hosted version? Self-hosted version, nightly 2021-02-01.

What platform are you using? Desktop -- Brave Browser, Mac OS X Mojave.

Bale001 commented 3 years ago

There is a similar bug #2914 which I believe might be related to this... just a guess though after reading through the SWF with JPEX

bls1999 commented 3 years ago

There is a similar bug #2914 which I believe might be related to this... just a guess though after reading through the SWF with JPEX

That seems like a good bet, seeing as this is probably a movieclip looping error and not sound and visuals separately. This might also help explain the cause of the other one. Good catch!

n0samu commented 2 years ago

This happens because the onUnload handler of the tankShell sprite is being called multiple times when the sprite is removed. Here is the relevant code for the explosion sound effect:

this.onUnload = function()
{
   var _loc1_ = this;
   var _loc2_ = _root;
   m = _loc2_.cam.explosions.attachMovie("tankShellExplosion","shell" + _loc2_.flameLevel(),_loc2_.flameLevel());
   m._x = _loc1_._x;
   m._y = _loc1_._y;
   m._rotation = _loc1_._rotation;
};

If we add a trace statement here, it becomes clear that the handler is called many times when the shell is destroyed, whereas in Flash Player it's only called once.

bls1999 commented 1 year ago

Great find, @n0samu! I added that trace statement and it appears that is indeed what's happening.