From 395f89c9732ed4d6c23f6742dc5d1dfe3312e5e8 Mon Sep 17 00:00:00 2001 From: David Quintana Date: Tue, 20 Oct 2020 13:24:12 +0200 Subject: [PATCH] Fix resource leak in the OBJ loader. --- .../client/model/obj/OBJLoader.java | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/src/main/java/net/minecraftforge/client/model/obj/OBJLoader.java b/src/main/java/net/minecraftforge/client/model/obj/OBJLoader.java index a2329ab4c..d66998683 100644 --- a/src/main/java/net/minecraftforge/client/model/obj/OBJLoader.java +++ b/src/main/java/net/minecraftforge/client/model/obj/OBJLoader.java @@ -30,6 +30,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.IModelLoader; import javax.annotation.Nullable; +import java.io.FileNotFoundException; import java.io.IOException; import java.util.*; @@ -71,20 +72,16 @@ public class OBJLoader implements IModelLoader public OBJModel loadModel(OBJModel.ModelSettings settings) { return modelCache.computeIfAbsent(settings, (data) -> { - IResource resource; - try - { - resource = manager.getResource(settings.modelLocation); - } - catch (IOException e) - { - throw new RuntimeException("Could not find OBJ model", e); - } - try(LineReader rdr = new LineReader(resource)) + try(IResource resource = manager.getResource(settings.modelLocation); + LineReader rdr = new LineReader(resource)) { return new OBJModel(rdr, settings); } + catch (FileNotFoundException e) + { + throw new RuntimeException("Could not find OBJ model", e); + } catch (Exception e) { throw new RuntimeException("Could not read OBJ model", e); @@ -95,20 +92,15 @@ public class OBJLoader implements IModelLoader public MaterialLibrary loadMaterialLibrary(ResourceLocation materialLocation) { return materialCache.computeIfAbsent(materialLocation, (location) -> { - IResource resource; - try - { - resource = manager.getResource(location); - } - catch (IOException e) - { - throw new RuntimeException("Could not find OBJ material library", e); - } - - try(LineReader rdr = new LineReader(resource)) + try(IResource resource = manager.getResource(location); + LineReader rdr = new LineReader(resource)) { return new MaterialLibrary(rdr); } + catch (FileNotFoundException e) + { + throw new RuntimeException("Could not find OBJ material library", e); + } catch (Exception e) { throw new RuntimeException("Could not read OBJ material library", e);