Catch (nearly) all exceptions thrown by OsuParser.
- Properly handle bad input and log a warning. The game may run with some gameplay errors (ex. if no base TimingPoint is parsed), but it should not crash. Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
parent
39dcdf6dee
commit
83e486054f
|
@ -133,6 +133,7 @@ public class OsuParser {
|
|||
break;
|
||||
if ((tokens = tokenize(line)) == null)
|
||||
continue;
|
||||
try {
|
||||
switch (tokens[0]) {
|
||||
case "AudioFilename":
|
||||
osu.audioFilename = new File(file.getParent() + File.separator + tokens[1]);
|
||||
|
@ -174,6 +175,10 @@ public class OsuParser {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.warn(String.format("Failed to read line '%s' for file '%s'.",
|
||||
line, file.getAbsolutePath()), e);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "[Editor]":
|
||||
|
@ -186,6 +191,7 @@ public class OsuParser {
|
|||
/* Not implemented. */
|
||||
// if ((tokens = tokenize(line)) == null)
|
||||
// continue;
|
||||
// try {
|
||||
// switch (tokens[0]) {
|
||||
// case "Bookmarks":
|
||||
// String[] bookmarks = tokens[1].split(",");
|
||||
|
@ -207,6 +213,10 @@ public class OsuParser {
|
|||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// Log.warn(String.format("Failed to read editor line '%s' for file '%s'.",
|
||||
// line, file.getAbsolutePath()), e);
|
||||
// }
|
||||
}
|
||||
break;
|
||||
|
@ -219,6 +229,7 @@ public class OsuParser {
|
|||
break;
|
||||
if ((tokens = tokenize(line)) == null)
|
||||
continue;
|
||||
try {
|
||||
switch (tokens[0]) {
|
||||
case "Title":
|
||||
osu.title = tokens[1];
|
||||
|
@ -251,6 +262,10 @@ public class OsuParser {
|
|||
osu.beatmapSetID = Integer.parseInt(tokens[1]);
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.warn(String.format("Failed to read metadata '%s' for file '%s'.",
|
||||
line, file.getAbsolutePath()), e);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "[Difficulty]":
|
||||
|
@ -262,6 +277,7 @@ public class OsuParser {
|
|||
break;
|
||||
if ((tokens = tokenize(line)) == null)
|
||||
continue;
|
||||
try {
|
||||
switch (tokens[0]) {
|
||||
case "HPDrainRate":
|
||||
osu.HPDrainRate = Float.parseFloat(tokens[1]);
|
||||
|
@ -282,6 +298,10 @@ public class OsuParser {
|
|||
osu.sliderTickRate = Float.parseFloat(tokens[1]);
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.warn(String.format("Failed to read difficulty '%s' for file '%s'.",
|
||||
line, file.getAbsolutePath()), e);
|
||||
}
|
||||
}
|
||||
if (osu.approachRate == -1f) // not in old format
|
||||
osu.approachRate = osu.overallDifficulty;
|
||||
|
@ -302,10 +322,15 @@ public class OsuParser {
|
|||
osu.bg = file.getParent() + File.separator + tokens[2];
|
||||
break;
|
||||
case "2": // break periods
|
||||
try {
|
||||
if (osu.breaks == null) // optional, create if needed
|
||||
osu.breaks = new ArrayList<Integer>();
|
||||
osu.breaks.add(Integer.parseInt(tokens[1]));
|
||||
osu.breaks.add(Integer.parseInt(tokens[2]));
|
||||
} catch (Exception e) {
|
||||
Log.warn(String.format("Failed to read break period '%s' for file '%s'.",
|
||||
line, file.getAbsolutePath()), e);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* Not implemented. */
|
||||
|
@ -321,6 +346,7 @@ public class OsuParser {
|
|||
if (line.charAt(0) == '[')
|
||||
break;
|
||||
|
||||
try {
|
||||
// parse timing point
|
||||
OsuTimingPoint timingPoint = new OsuTimingPoint(line);
|
||||
|
||||
|
@ -336,6 +362,10 @@ public class OsuParser {
|
|||
}
|
||||
|
||||
osu.timingPoints.add(timingPoint);
|
||||
} catch (Exception e) {
|
||||
Log.warn(String.format("Failed to read timing point '%s' for file '%s'.",
|
||||
line, file.getAbsolutePath()), e);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "[Colours]":
|
||||
|
@ -348,6 +378,7 @@ public class OsuParser {
|
|||
break;
|
||||
if ((tokens = tokenize(line)) == null)
|
||||
continue;
|
||||
try {
|
||||
switch (tokens[0]) {
|
||||
case "Combo1":
|
||||
case "Combo2":
|
||||
|
@ -366,6 +397,10 @@ public class OsuParser {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.warn(String.format("Failed to read color '%s' for file '%s'.",
|
||||
line, file.getAbsolutePath()), e);
|
||||
}
|
||||
}
|
||||
if (!colors.isEmpty())
|
||||
osu.combo = colors.toArray(new Color[colors.size()]);
|
||||
|
@ -380,6 +415,7 @@ public class OsuParser {
|
|||
break;
|
||||
/* Only type counts parsed at this time. */
|
||||
tokens = line.split(",");
|
||||
try {
|
||||
type = Integer.parseInt(tokens[3]);
|
||||
if ((type & OsuHitObject.TYPE_CIRCLE) > 0)
|
||||
osu.hitObjectCircle++;
|
||||
|
@ -387,8 +423,13 @@ public class OsuParser {
|
|||
osu.hitObjectSlider++;
|
||||
else //if ((type & OsuHitObject.TYPE_SPINNER) > 0)
|
||||
osu.hitObjectSpinner++;
|
||||
} catch (Exception e) {
|
||||
Log.warn(String.format("Failed to read hit object '%s' for file '%s'.",
|
||||
line, file.getAbsolutePath()), e);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// map length = last object end time (TODO: end on slider?)
|
||||
if ((type & OsuHitObject.TYPE_SPINNER) > 0) {
|
||||
// some 'endTime' fields contain a ':' character (?)
|
||||
|
@ -398,6 +439,10 @@ public class OsuParser {
|
|||
osu.endTime = Integer.parseInt(tokens[5]);
|
||||
} else if (type != 0)
|
||||
osu.endTime = Integer.parseInt(tokens[2]);
|
||||
} catch (Exception e) {
|
||||
Log.warn(String.format("Failed to read hit object end time '%s' for file '%s'.",
|
||||
line, file.getAbsolutePath()), e);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
line = in.readLine();
|
||||
|
@ -463,6 +508,7 @@ public class OsuParser {
|
|||
if (tokenCount < 4)
|
||||
continue;
|
||||
|
||||
try {
|
||||
// create a new OsuHitObject for each line
|
||||
OsuHitObject hitObject = new OsuHitObject(line);
|
||||
|
||||
|
@ -477,6 +523,10 @@ public class OsuParser {
|
|||
hitObject.setComboNumber(comboNumber++);
|
||||
|
||||
osu.objects[objectIndex++] = hitObject;
|
||||
} catch (Exception e) {
|
||||
Log.warn(String.format("Failed to read hit object '%s' for OsuFile '%s'.",
|
||||
line, osu.toString()), e);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.error(String.format("Failed to read file '%s'.", osu.getFile().getAbsolutePath()), e);
|
||||
|
|
|
@ -755,6 +755,7 @@ public class Game extends BasicGameState {
|
|||
breakTime = 0;
|
||||
breakSound = false;
|
||||
timingPointIndex = 0;
|
||||
beatLengthBase = beatLength = 1;
|
||||
pauseTime = -1;
|
||||
pausedMouseX = -1;
|
||||
pausedMouseY = -1;
|
||||
|
|
Loading…
Reference in New Issue
Block a user