From 32f67770aba5a40aa36f14388559cc63f0da3683 Mon Sep 17 00:00:00 2001 From: CloneWith Date: Mon, 26 Aug 2024 12:31:30 +0800 Subject: [PATCH] Fix NPE caused by null storyboard background --- src/itdelatrisu/opsu/states/Game.java | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/itdelatrisu/opsu/states/Game.java b/src/itdelatrisu/opsu/states/Game.java index 248c691a..5e94773c 100644 --- a/src/itdelatrisu/opsu/states/Game.java +++ b/src/itdelatrisu/opsu/states/Game.java @@ -343,7 +343,7 @@ public void init(GameContainer container, StateBasedGame game) int width = container.getWidth(); int height = container.getHeight(); - // create offscreen graphics + // create off-screen graphics offscreen = new Image(width, height); gOffscreen = offscreen.getGraphics(); gOffscreen.setBackground(Color.black); @@ -403,10 +403,13 @@ else if (deathTime > -1) // "Easy" mod: health bar increasing if (Options.isDefaultPlayfieldForced() || !beatmap.drawBackground(width, height, 0, 0, dimLevel, storyboard == null)) { Image bg = GameImage.MENU_BG.getImage(); bg.setAlpha(dimLevel); - Color bgColors = storyboard.getBackgroundColor(); - if (bgColors != null) - bg.setImageColor(bgColors.r, bgColors.g, bgColors.b, bgColors.a); - bg.drawCentered(width / 2, height / 2); + if (storyboard != null) + { + Color bgColors = storyboard.getBackgroundColor(); + if (bgColors != null) + bg.setImageColor(bgColors.r, bgColors.g, bgColors.b, bgColors.a); + } + bg.drawCentered(width / 2f, height / 2f); bg.setAlpha(1f); } } @@ -437,24 +440,22 @@ else if (deathTime > -1) // "Easy" mod: health bar increasing // Auto relevant mods: move cursor automatically // TODO: this should really be in update(), not render() - autoMousePosition.set((float) width / 2, (float) height / 2); + // autoMousePosition.set((float) width / 2, (float) height / 2); autoMousePressed = false; if (GameMod.AUTO.isActive() || GameMod.AUTOPILOT.isActive() || GameMod.CINEMA.isActive()) { Vec2f autoPoint = null; - if (gameFinished) { - // game finished, do nothing - } else if (isLeadIn()) { + if (!gameFinished && isLeadIn()) { // lead-in float progress = Math.max((float) (leadInTime - beatmap.audioLeadIn) / approachTime, 0f); autoMousePosition.y = height / (2f - progress); - } else if (objectIndex == 0 && trackPosition < firstObjectTime) { + } else if (!gameFinished && objectIndex == 0 && trackPosition < firstObjectTime) { // before first object timeDiff = firstObjectTime - trackPosition; if (timeDiff < approachTime) { Vec2f point = gameObjects[0].getPointAt(trackPosition); autoPoint = getPointAt(autoMousePosition.x, autoMousePosition.y, point.x, point.y, 1f - ((float) timeDiff / approachTime)); } - } else if (objectIndex < beatmap.objects.length) { + } else if (!gameFinished && objectIndex < beatmap.objects.length) { // normal object int objectTime = beatmap.objects[objectIndex].getTime(); if (trackPosition < objectTime) { @@ -2220,9 +2221,7 @@ private void runReplayFrame(ReplayFrame frame){ int deltaKeys = (keys & ~lastReplayKeys); // keys that turned on if (deltaKeys != ReplayFrame.KEY_NONE) // send a key press sendGameKeyPress(deltaKeys, replayX, replayY, frame.getTime()); - else if (keys != lastReplayKeys) - ; // do nothing - else + else if (keys == lastReplayKeys) updateGame(replayX, replayY, frame.getTimeDiff(), frame.getTime(), keys); lastReplayKeys = keys; }