Better error handling for Replay.load().

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-03-12 01:18:50 -04:00
parent c53679fe63
commit 87323533af
3 changed files with 23 additions and 15 deletions

View File

@ -118,20 +118,17 @@ public class Replay {
/** /**
* Loads the replay data. * Loads the replay data.
* @throws IOException failure to load the data
*/ */
public void load() { public void load() throws IOException {
if (loaded) if (loaded)
return; return;
try {
OsuReader reader = new OsuReader(file); OsuReader reader = new OsuReader(file);
loadHeader(reader); loadHeader(reader);
loadData(reader); loadData(reader);
reader.close(); reader.close();
loaded = true; loaded = true;
} catch (IOException e) {
ErrorHandler.error("Could not load replay data.", e, true);
}
} }
/** /**

View File

@ -1186,7 +1186,7 @@ public class Game extends BasicGameState {
this.replay = null; this.replay = null;
} else { } else {
if (replay.frames == null) { if (replay.frames == null) {
ErrorHandler.error("Invalid replay.", null, false); ErrorHandler.error("Attempting to set a replay with no frames.", null, false);
return; return;
} }
this.isReplay = true; this.isReplay = true;

View File

@ -31,6 +31,9 @@ import itdelatrisu.opsu.audio.SoundController;
import itdelatrisu.opsu.audio.SoundEffect; import itdelatrisu.opsu.audio.SoundEffect;
import itdelatrisu.opsu.replay.Replay; import itdelatrisu.opsu.replay.Replay;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.lwjgl.opengl.Display; import org.lwjgl.opengl.Display;
import org.newdawn.slick.Color; import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer; import org.newdawn.slick.GameContainer;
@ -42,6 +45,7 @@ import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame; import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.state.transition.FadeInTransition; import org.newdawn.slick.state.transition.FadeInTransition;
import org.newdawn.slick.state.transition.FadeOutTransition; import org.newdawn.slick.state.transition.FadeOutTransition;
import org.newdawn.slick.util.Log;
/** /**
* "Game Ranking" (score card) state. * "Game Ranking" (score card) state.
@ -168,10 +172,17 @@ public class GameRanking extends BasicGameState {
if (replayButton.contains(x, y)) { if (replayButton.contains(x, y)) {
Replay r = data.getReplay(null); Replay r = data.getReplay(null);
if (r != null) { if (r != null) {
try {
r.load(); r.load();
gameState.setReplay(r); gameState.setReplay(r);
gameState.setRestart((data.isGameplay()) ? Game.Restart.REPLAY : Game.Restart.NEW); gameState.setRestart((data.isGameplay()) ? Game.Restart.REPLAY : Game.Restart.NEW);
returnToGame = true; returnToGame = true;
} catch (FileNotFoundException e) {
UI.sendBarNotification("Replay file not found.");
} catch (IOException e) {
Log.error("Failed to load replay data.", e);
UI.sendBarNotification("Failed to load replay data. See log for details.");
}
} else } else
UI.sendBarNotification("Replay file not found."); UI.sendBarNotification("Replay file not found.");
} }