Skip to content

Commit

Permalink
Merge pull request #458 from Reco1I/fix-perfect
Browse files Browse the repository at this point in the history
Fix potential IllegalStateException when setting video playback speed below 0.01
  • Loading branch information
Rian8337 authored Nov 23, 2024
2 parents c99aab5 + f4585f8 commit 62b2414
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/ru/nsu/ccfit/zuev/osu/game/GameScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -2263,8 +2263,12 @@ public void gameover() {

float initialFrequency = songService.getFrequency();

// Wind down animation for failing based on osu!stable behavior.
// Locally saving the scenes references to avoid unexpected behavior when the scene is changed.
ExtendedScene scene = this.scene;
ExtendedScene mgScene = this.mgScene;
ExtendedScene bgScene = this.bgScene;

// Wind down animation for failing based on osu!stable behavior.
engine.registerUpdateHandler(new IUpdateHandler() {
private float elapsedTime;

Expand All @@ -2290,6 +2294,13 @@ private void applyEffectToScene(Scene scene) {

@Override
public void onUpdate(float pSecondsElapsed) {

// Ensure this update handler is removed under unexpected circumstances.
if (engine.getScene() != scene) {
engine.unregisterUpdateHandler(this);
return;
}

elapsedTime += pSecondsElapsed;

// In osu!stable, the update is capped to 60 FPS. This means in higher framerates, the animations
Expand All @@ -2311,8 +2322,11 @@ public void onUpdate(float pSecondsElapsed) {
float decreasedSpeed = GameHelper.getSpeedMultiplier() * (1 - (initialFrequency - decreasedFrequency) / initialFrequency);

scene.setTimeMultiplier(decreasedSpeed);

if (video != null) {
video.setPlaybackSpeed(decreasedSpeed);
// Aparently MediaPlayer API doesn't support setting playback speed
// below 0.01 causing an IllegalStateException.
video.setPlaybackSpeed(Math.max(0.01f, decreasedSpeed));
}

songService.setFrequencyForcefully(decreasedFrequency);
Expand Down

0 comments on commit 62b2414

Please sign in to comment.