fix: game crashes when asset index file is empty

This commit is contained in:
huanghongxun
2020-02-20 14:22:55 +08:00
parent 0a68e52fca
commit 5c19dcd208

View File

@@ -93,13 +93,12 @@ public final class GameAssetDownloadTask extends Task<Void> {
public void execute() throws Exception { public void execute() throws Exception {
AssetIndex index; AssetIndex index;
try { try {
index = JsonUtils.GSON.fromJson(FileUtils.readText(assetIndexFile), AssetIndex.class); index = JsonUtils.fromNonNullJson(FileUtils.readText(assetIndexFile), AssetIndex.class);
} catch (IOException | JsonSyntaxException e) { } catch (IOException | JsonParseException e) {
throw new GameAssetIndexDownloadTask.GameAssetIndexMalformedException(); throw new GameAssetIndexDownloadTask.GameAssetIndexMalformedException();
} }
int progress = 0; int progress = 0;
if (index != null)
for (AssetObject assetObject : index.getObjects().values()) { for (AssetObject assetObject : index.getObjects().values()) {
if (isCancelled()) if (isCancelled())
throw new InterruptedException(); throw new InterruptedException();