Fixed a null pointer exception. (blame: 92f4a51)

This occurred when inserting beatmaps with null "bg" field into the database.

Also moved LOAD_HD_IMAGES option from "Custom" tab to "Display".

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-06-11 13:42:57 -04:00
parent 92f4a5176d
commit 44da08d7a1
5 changed files with 11 additions and 8 deletions

View File

@ -390,7 +390,7 @@ public enum GameImage {
private static final int UNSCALED_HEIGHT = 768; private static final int UNSCALED_HEIGHT = 768;
/** Filename suffix for HD images. */ /** Filename suffix for HD images. */
private static final String HD_SUFFIX = "@2x"; public static final String HD_SUFFIX = "@2x";
/** Image HD/SD suffixes. */ /** Image HD/SD suffixes. */
private static final String[] private static final String[]

View File

@ -284,7 +284,7 @@ public class Options {
}, },
ENABLE_THEME_SONG ("Enable Theme Song", "Whether to play the theme song upon starting opsu!", true), ENABLE_THEME_SONG ("Enable Theme Song", "Whether to play the theme song upon starting opsu!", true),
SHOW_HIT_ERROR_BAR ("Show Hit Error Bar", "Shows precisely how accurate you were with each hit.", false), SHOW_HIT_ERROR_BAR ("Show Hit Error Bar", "Shows precisely how accurate you were with each hit.", false),
LOAD_HD_IMAGES ("Load HD Images", "Loads HD (@2x) images when available. Increases memory usage and loading times.", true), LOAD_HD_IMAGES ("Load HD Images", String.format("Loads HD (%s) images when available. Increases memory usage and loading times.", GameImage.HD_SUFFIX), true),
DISABLE_MOUSE_WHEEL ("Disable mouse wheel in play mode", "During play, you can use the mouse wheel to adjust the volume and pause the game.\nThis will disable that functionality.", false), DISABLE_MOUSE_WHEEL ("Disable mouse wheel in play mode", "During play, you can use the mouse wheel to adjust the volume and pause the game.\nThis will disable that functionality.", false),
DISABLE_MOUSE_BUTTONS ("Disable mouse buttons in play mode", "This option will disable all mouse buttons.\nSpecifically for people who use their keyboard to click.", false); DISABLE_MOUSE_BUTTONS ("Disable mouse buttons in play mode", "This option will disable all mouse buttons.\nSpecifically for people who use their keyboard to click.", false);

View File

@ -63,7 +63,7 @@ public class BeatmapImageCache {
/** /**
* Returns the image mapped to the specified beatmap. * Returns the image mapped to the specified beatmap.
* @param beatmap the Beatmap * @param beatmap the Beatmap
* @return the Image, or {@code null} if no such mapping exists * @return the Image, or {@code null} if no such mapping exists
*/ */
public Image get(Beatmap beatmap) { return cache.get(beatmap.bg); } public Image get(Beatmap beatmap) { return cache.get(beatmap.bg); }

View File

@ -335,7 +335,7 @@ public class BeatmapDB {
stmt.setBoolean(33, beatmap.letterboxInBreaks); stmt.setBoolean(33, beatmap.letterboxInBreaks);
stmt.setBoolean(34, beatmap.widescreenStoryboard); stmt.setBoolean(34, beatmap.widescreenStoryboard);
stmt.setBoolean(35, beatmap.epilepsyWarning); stmt.setBoolean(35, beatmap.epilepsyWarning);
stmt.setString(36, beatmap.bg.getName()); stmt.setString(36, (beatmap.bg == null) ? null : beatmap.bg.getName());
stmt.setString(37, beatmap.sliderBorderToString()); stmt.setString(37, beatmap.sliderBorderToString());
stmt.setString(38, beatmap.timingPointsToString()); stmt.setString(38, beatmap.timingPointsToString());
stmt.setString(39, beatmap.breaksToString()); stmt.setString(39, beatmap.breaksToString());
@ -444,6 +444,7 @@ public class BeatmapDB {
*/ */
private static void setBeatmapFields(ResultSet rs, Beatmap beatmap) throws SQLException { private static void setBeatmapFields(ResultSet rs, Beatmap beatmap) throws SQLException {
try { try {
File dir = beatmap.getFile().getParentFile();
beatmap.beatmapID = rs.getInt(4); beatmap.beatmapID = rs.getInt(4);
beatmap.beatmapSetID = rs.getInt(5); beatmap.beatmapSetID = rs.getInt(5);
beatmap.title = BeatmapParser.getDBString(rs.getString(6)); beatmap.title = BeatmapParser.getDBString(rs.getString(6));
@ -466,7 +467,7 @@ public class BeatmapDB {
beatmap.bpmMin = rs.getInt(23); beatmap.bpmMin = rs.getInt(23);
beatmap.bpmMax = rs.getInt(24); beatmap.bpmMax = rs.getInt(24);
beatmap.endTime = rs.getInt(25); beatmap.endTime = rs.getInt(25);
beatmap.audioFilename = new File(beatmap.getFile().getParentFile(), BeatmapParser.getDBString(rs.getString(26))); beatmap.audioFilename = new File(dir, BeatmapParser.getDBString(rs.getString(26)));
beatmap.audioLeadIn = rs.getInt(27); beatmap.audioLeadIn = rs.getInt(27);
beatmap.previewTime = rs.getInt(28); beatmap.previewTime = rs.getInt(28);
beatmap.countdown = rs.getByte(29); beatmap.countdown = rs.getByte(29);
@ -476,7 +477,9 @@ public class BeatmapDB {
beatmap.letterboxInBreaks = rs.getBoolean(33); beatmap.letterboxInBreaks = rs.getBoolean(33);
beatmap.widescreenStoryboard = rs.getBoolean(34); beatmap.widescreenStoryboard = rs.getBoolean(34);
beatmap.epilepsyWarning = rs.getBoolean(35); beatmap.epilepsyWarning = rs.getBoolean(35);
beatmap.bg = new File(beatmap.getFile().getParentFile(), BeatmapParser.getDBString(rs.getString(36))); String bg = rs.getString(36);
if (bg != null)
beatmap.bg = new File(dir, BeatmapParser.getDBString(rs.getString(36)));
beatmap.sliderBorderFromString(rs.getString(37)); beatmap.sliderBorderFromString(rs.getString(37));
} catch (SQLException e) { } catch (SQLException e) {
throw e; throw e;

View File

@ -59,6 +59,7 @@ public class OptionsMenu extends BasicGameState {
GameOption.SCREENSHOT_FORMAT, GameOption.SCREENSHOT_FORMAT,
GameOption.NEW_CURSOR, GameOption.NEW_CURSOR,
GameOption.DYNAMIC_BACKGROUND, GameOption.DYNAMIC_BACKGROUND,
GameOption.LOAD_HD_IMAGES,
GameOption.LOAD_VERBOSE GameOption.LOAD_VERBOSE
}), }),
MUSIC ("Music", new GameOption[] { MUSIC ("Music", new GameOption[] {
@ -91,8 +92,7 @@ public class OptionsMenu extends BasicGameState {
GameOption.FIXED_HP, GameOption.FIXED_HP,
GameOption.FIXED_AR, GameOption.FIXED_AR,
GameOption.FIXED_OD, GameOption.FIXED_OD,
GameOption.CHECKPOINT, GameOption.CHECKPOINT
GameOption.LOAD_HD_IMAGES
}); });
/** Total number of tabs. */ /** Total number of tabs. */