ruffle-rs / ruffle

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

Error on https://archive.org/details/flash_clickmaze2 #8427

Closed n0samu closed 2 months ago

n0samu commented 1 year ago

Error Info

Error name: Error Error message: panicked at 'assertion failed: (left == right) left: true, right: false: cannot recursively acquire mutex', /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/sys/wasm/../unsupported/locks/mutex.rs:24:9 Error stack:

966/W/n.wbg.__wbg_new_df6e6ab7a65c4c4d@https://cors.archive.org/cors/emularity_engine_v1/core.ruffle.9f799b172fb83660e1a8.js:1:5314
std::sync::once::Once::call_once::{{closure}}::ha360d592741a73b3@:wasm-function[1138]:0x2c083f
std::sync::once::Once::call_inner::h00971925aa1adad3@:wasm-function[1447]:0x320287
core::ops::function::FnOnce::call_once{{vtable.shim}}::h613b00154d20bc2b@:wasm-function[4879]:0x478fc0
std::panicking::rust_panic_with_hook::h84feca33bd4bd229@:wasm-function[3630]:0x441860
core::panicking::panic_fmt::hc171d095bc4a492d@:wasm-function[5070]:0x47f7eb
core::panicking::assert_failed_inner::h339711ce35c9630e@:wasm-function[2257]:0x3c4b3e
core::panicking::assert_failed::h8533577e745afe54@:wasm-function[4743]:0x475cea
<core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hda7b54b2eff36a1b@:wasm-function[1057]:0x2ab551
<core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h47a61d314cde7a06@:wasm-function[998]:0x2928db
wasm_bindgen_futures::queue::Queue::new::{{closure}}::hc6462560cc4902d7@:wasm-function[2279]:0x3c8a3b
<dyn core::ops::function::FnMut<(A,)>+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::hf159a97fdda8e3db@:wasm-function[5441]:0x48943b
closure2936 externref shim@:wasm-function[5566]:0x48bba8
S@https://cors.archive.org/cors/emularity_engine_v1/core.ruffle.9f799b172fb83660e1a8.js:1:2706
c@https://cors.archive.org/cors/emularity_engine_v1/core.ruffle.9f799b172fb83660e1a8.js:1:2231
966/W/n.wbg.__wbg_open_ab0998e8eb242a30/<@https://cors.archive.org/cors/emularity_engine_v1/core.ruffle.9f799b172fb83660e1a8.js:1:11315
R@https://cors.archive.org/cors/emularity_engine_v1/core.ruffle.9f799b172fb83660e1a8.js:1:2859
966/W/n.wbg.__wbg_open_ab0998e8eb242a30@https://cors.archive.org/cors/emularity_engine_v1/core.ruffle.9f799b172fb83660e1a8.js:1:11282
<ruffle_web::navigator::WebNavigatorBackend as ruffle_core::backend::navigator::NavigatorBackend>::navigate_to_url::hd9b11868a3319732@:wasm-function[499]:0x18a2bb
ruffle_core::avm1::activation::Activation::run_actions::hf56a4f05c9ada183@:wasm-function[289]:0xf497
ruffle_core::avm1::function::Executable::exec::hdfddf9496055cb0e@:wasm-function[359]:0xe69ea
<ruffle_core::avm1::object::Object as ruffle_core::avm1::object::TObject>::call_method::h15e49bfbb24125b9@:wasm-function[850]:0x256686
ruffle_core::avm1::runtime::Avm1::run_stack_frame_for_method::h24d22333e11b8363@:wasm-function[1888]:0x387b78
ruffle_core::player::Player::run_actions::h94ee2c622e20a24f@:wasm-function[488]:0x183768
ruffle_core::player::Player::update_mouse_state::h5919d51136590b6e@:wasm-function[323]:0xb46b0
ruffle_core::player::Player::handle_event::h5b3e6822f1bf9486@:wasm-function[309]:0x7947e
ruffle_web::Ruffle::new_internal::{{closure}}::{{closure}}::{{closure}}::h5867cd196f77303d@:wasm-function[962]:0x2880a0
<dyn core::ops::function::FnMut<(A,)>+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::h242c0575732f852b@:wasm-function[5435]:0x489385
closure379 externref shim@:wasm-function[5567]:0x48bbbd
x@https://cors.archive.org/cors/emularity_engine_v1/core.ruffle.9f799b172fb83660e1a8.js:1:2501
c@https://cors.archive.org/cors/emularity_engine_v1/core.ruffle.9f799b172fb83660e1a8.js:1:2231

Player Info

Allows script access: false Renderer: WebGL

Page Info

Page URL: https://archive.org/details/flash_clickmaze2

Browser Info

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:106.0) Gecko/20100101 Firefox/106.0 Platform: Win32 Has touch support: true

Ruffle Info

Version: 0.1.0 Name: nightly 2022-09-19 Channel: nightly Built: 2022-09-19T00:15:10.357Z Commit: 9b9c95bfe28cb862d44e9517e94e9de73acd9de3 Is extension: false

Metadata

width: 500 height: 435 frameRate: 60 numFrames: 1802 swfVersion: 10 backgroundColor: #003CC6 isActionScript3: false uncompressedLength: 714268

n0samu commented 1 year ago

This error occurs every time I click the "Like Us on Facebook" button on the game's main menu.

n0samu commented 1 year ago

Here is the relevant code on frame 3 of the SWF:

stop();
facebook_btn.onPress = function()
{
   Playtomic.Log.CustomMetric("Main Menu - Like Button");
   Playtomic.Log.ForceSend();
   getUrl("http://www.facebook.com/gideovames", "_blank");
};

I found several ways to stop this error from occurring:

Browser devtools (Network tab) show that the Playtomic request is never actually sent, even if the getUrl call is before the ForceSend call. If the getUrl call is removed, then the Playtomic network request is sent as normal.

On the other hand, no error happens in the Ruffle desktop app. The desktop app only logs the following warning: WARN isahc::handler] request completed with error: failed to resolve host name

My conclusion is that Ruffle's web Navigator backend must try to acquire an exclusive lock when opening webpages via getUrl. And it seems like the Playtomic network request already acquired a lock on the same object, so the getUrl call crashes Ruffle. If we reverse the order, the network request fails to acquire the lock instead, but that just fails silently instead of crashing Ruffle.

kmeisthax commented 1 year ago

The "recursive lock" type errors tend to happen after the player has already panicked, so I tend to be suspicious that the true cause was buried under other log lines. However, I do have an idea of how this can happen: namely, in web/src/navigator.rs:191 we grab the current window, and then construct a request, and then we await the request.

If web_sys has internal locks on window, then that's a potential explanation for the bug. We didn't extinguish the window reference before awaiting.

I'm not currently at my normal dev box so I can't play around with this right now, though.

Toad06 commented 1 year ago

FWIW it seems possible to reproduce this issue with just two lines of code:

loadMovieNum("fake.swf",0,"GET"); // no need for fake.swf to exist
getURL("https://ruffle.rs","_blank","GET");

P-code:

Push "fake.swf" "_level0"
GetURL2 false false 1
Push "https://ruffle.rs" "_blank"
GetURL2 false false 1

Tested on Firefox.

n0samu commented 1 year ago

Found another game with this issue: https://www.kongregate.com/games/Scarybug/chronotron If you click "Bonus Levels" on the main menu, then "Click here to play these levels on Kongregate", the game will crash. For some reason the panic screen doesn't show, but the console has the same error.

n0samu commented 1 year ago

Found yet another one: https://archive.org/details/warlords-calltoarms Click "Play More Games" on the main menu and the error will occur.

n0samu commented 1 year ago

I just tested all of these games in Edge (Chromium) and the errors did not occur at all. I think this is some strange Firefox bug.

Also, for each of the games I activated "Pause on exceptions" in Firefox's Developer Tools. Here's what I found:

n0samu commented 1 year ago

With #8846, the panic screen now shows for all 3 games. Nothing else has changed.

n0samu commented 1 year ago

Clicking the Ludobox.com splash screen logo in Track the Ball also causes the same error.

n0samu commented 7 months ago

Starting file downloads on a tab with a Ruffle player seems to sometimes trigger a similar bug in Firefox. For example, going to https://n0samu.github.io/ruffle-testing/?swf=homesheephome.swf , then removing ?swf= from the URL and pressing Enter (to trigger a file download for the SWF) often makes the Ruffle player either panic or freeze.