Avoid a crash when reading malformed .mt files

color component values greater than 255 would cause the app to crash
master
Treer 2018-04-22 19:08:49 +10:00
parent e7c328b0ae
commit 44ea73d3e7
2 changed files with 14 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package amidst.gameengineabstraction.world.biome;
import amidst.documentation.GsonConstructor;
import amidst.logging.AmidstLogger;
import amidst.mojangapi.world.biome.BiomeColor;
import amidst.settings.biomeprofile.BiomeColorJson;
@ -50,8 +51,14 @@ public abstract class BiomeBase implements IBiome {
public BiomeColor getDefaultColor() {
if (defaultColor == null) {
// Must have been deserialized rather than constructed
defaultColor = BiomeColor.fromBiomeColorJson(color);
try {
// Must have been deserialized rather than constructed
defaultColor = BiomeColor.fromBiomeColorJson(color);
} catch(IllegalArgumentException ex) {
// badly formatted data file
AmidstLogger.error("Biome \"" + name + "\" has invalid colour");
defaultColor = BiomeColor.error();
}
}
return defaultColor;
}

View File

@ -19,7 +19,12 @@ public class BiomeColor {
return UNKNOWN_BIOME_COLOR;
}
public static BiomeColor error() {
return ERROR_BIOME_COLOR;
}
private static final BiomeColor UNKNOWN_BIOME_COLOR = new BiomeColor(0, 0, 0);
private static final BiomeColor ERROR_BIOME_COLOR = new BiomeColor(255, 0, 255);
private static final int DESELECT_NUMBER = 30;
private static final int LIGHTEN_BRIGHTNESS = 40;