ruffle-rs / ruffle

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

Bubble Trouble: Score not shown #9325

Open n0samu opened 1 year ago

n0samu commented 1 year ago

Describe the bug

In Bubble Trouble, after you beat the first level, your score disappears and never reappears. image

It doesn't show on the Game Over screen, either. image

Expected behavior

Your score is supposed to be shown on both screens. image image

Affected platform

Self-hosted version

Operating system

Windows 10

Browser

Firefox 109

Additional information

The problem also happens in the desktop app for me.

Dinnerbone commented 1 year ago

I can't seem to reproduce, the score stays after I move to level 2 and when I reach the score screen. Both on desktop master & the build on newgrounds website.

n0samu commented 1 year ago

That's really weird. It's still happening for me right now. image I was testing the 1-player mode, but it also happens in the 2-player mode.

n0samu commented 1 year ago

Here's a video of what happens to me in case it helps somehow:

https://user-images.githubusercontent.com/71368227/215898032-bcf2c531-437c-4ada-88e6-b6d95dda4a05.mp4

n0samu commented 1 year ago

And here are the log messages I get on desktop:

WARN run_frame: ruffle_core::avm1::activation: RemoveSprite: Source is not a display object
WARN run_frame: ruffle_core::avm1::activation: RemoveSprite: Source is not a display object
WARN run_frame: ruffle_core::avm1::activation: RemoveSprite: Source is not a display object
WARN run_frame: ruffle_core::avm1::activation: RemoveSprite: Source is not a display object
n0samu commented 1 year ago

Summarizing my discussion with Dinnerbone on Discord below.

This is the offending code:

onClipEvent(enterFrame){
    onda = sada;
    sada = getTimer();
    _root.rate = (sada - onda) / 1000;
}

The SWF header shows that the game is set to run at 100 FPS. Ruffle can't hit that on my PC, so it's using a frame catchup mechanism to run the AS 100 times a second. The catchup mechanism ends up running the enterFrame code several times in a row, which means it gets called more than once per millisecond sometimes. That leads to _root.rate getting set to 0, and later the score is calculated like this (bodovi means points): _root.bodovi1 += Math.round(_root.timeleft._xscale / (_root.rate * 2000)); So infinity gets added to the player's score and it disappears since it can't be displayed. So the fix is to fake time advancing when doing the catchup, as seen in Dinnerbone's PR.

HaimZik commented 1 year ago

I see the issue on the demo page , on desktop the issues only happen with frame rate capping to 60. This game has frame rate of 100fps, on desktop ruffle it truly does 100fps but on Chrome it is throttled to 60fps. If I change the framerate to 60 the issues does not happen, on 61 frame rate it does happen(aside from desktop without frame rate capping). When the framerate is throttled ruffle always does catchup frames. This is avm2 swf that test total framed skipped and frame time, I believe it act the same way in avm1. FrameSkipTest.zip flash player: throttled 60fps, no frame skip ruffle desktop: not throttled(which is great), 3 skip frames on load time 0 on runtime. demo ruffle and ruffle desktop with frame rate capping: throttled 60fps, skip all the time. I limited the frame rate using Nvidia control panel image

n0samu commented 1 year ago

Thanks for putting together this demo, I think it will be quite helpful! On my PC, I'm seeing a lot of skipped frames even with the Ruffle desktop app. Do you think this is because my monitor has a refresh rate of 60 Hz?

HaimZik commented 1 year ago

Thanks for putting together this demo, I think it will be quite helpful! On my PC, I'm seeing a lot of skipped frames even with the Ruffle desktop app. Do you think this is because my monitor has a refresh rate of 60 Hz?

It because of vsync, if you disable vsync ruffle will do true 120fps.

HaimZik commented 1 year ago

FrameSkipTest.zip I have added a counter for frames with 0 time between them, when ruffle has frame rate capping it has frames with zero time between them. uncapped framerate ruffle has 2-3 at load time, it should be investigated if it causing longer load time. In Flash player if you do not move the mouse the counter will not rise, but with mouse movements or many clicks the counter infrequently rise, this bug should not be replicated in ruffle, it is a source of performance issue for stage3D apps in some mobile devices due to how vsync work in mobile devices.