diff --git a/Blarg.GameFramework/Graphics/Atlas/Json/TextureAtlasLoader.cs b/Blarg.GameFramework/Graphics/Atlas/Json/TextureAtlasLoader.cs index ae42e64..6414d91 100644 --- a/Blarg.GameFramework/Graphics/Atlas/Json/TextureAtlasLoader.cs +++ b/Blarg.GameFramework/Graphics/Atlas/Json/TextureAtlasLoader.cs @@ -10,12 +10,14 @@ namespace Blarg.GameFramework.Graphics.Atlas.Json { public static TextureAtlas Load(string file) { - var stream = Framework.FileSystem.Open(file); - string path = null; - if (file.Contains("/")) - path = file.Substring(0, file.LastIndexOf('/') + 1); - - return Load(stream, path); + using (var stream = Framework.FileSystem.Open(file)) + { + string path = null; + if (file.Contains("/")) + path = file.Substring(0, file.LastIndexOf('/') + 1); + + return Load(stream, path); + } } public static TextureAtlas Load(Stream file, string texturePath = null) @@ -25,6 +27,7 @@ namespace Blarg.GameFramework.Graphics.Atlas.Json var reader = new StreamReader(file); var definition = JsonConvert.DeserializeObject(reader.ReadToEnd()); + reader.Dispose(); if (definition.Texture == null) throw new ConfigFileException("No texture file specified."); diff --git a/Blarg.GameFramework/TileMap/Json/TileMapSerializer.cs b/Blarg.GameFramework/TileMap/Json/TileMapSerializer.cs index 466933c..d5254e7 100644 --- a/Blarg.GameFramework/TileMap/Json/TileMapSerializer.cs +++ b/Blarg.GameFramework/TileMap/Json/TileMapSerializer.cs @@ -32,6 +32,7 @@ namespace Blarg.GameFramework.TileMap.Json var reader = new StreamReader(file); var map = JsonConvert.DeserializeObject(reader.ReadToEnd()); + reader.Dispose(); if (map.Chunks == null || map.Chunks.Count == 0) throw new ConfigFileException("Invalid map: no chunks."); diff --git a/Blarg.GameFramework/TileMap/Meshes/Json/TileMeshCollectionLoader.cs b/Blarg.GameFramework/TileMap/Meshes/Json/TileMeshCollectionLoader.cs index 490ce72..fec15d8 100644 --- a/Blarg.GameFramework/TileMap/Meshes/Json/TileMeshCollectionLoader.cs +++ b/Blarg.GameFramework/TileMap/Meshes/Json/TileMeshCollectionLoader.cs @@ -11,12 +11,14 @@ namespace Blarg.GameFramework.TileMap.Meshes.Json { public static TileMeshCollection Load(string file, TextureAtlas atlas) { - var stream = Framework.FileSystem.Open(file); - string path = null; - if (file.Contains("/")) - path = file.Substring(0, file.LastIndexOf('/') + 1); - - return Load(stream, atlas, path); + using (var stream = Framework.FileSystem.Open(file)) + { + string path = null; + if (file.Contains("/")) + path = file.Substring(0, file.LastIndexOf('/') + 1); + + return Load(stream, atlas, path); + } } public static TileMeshCollection Load(Stream file, TextureAtlas atlas, string filePath = null) @@ -28,6 +30,7 @@ namespace Blarg.GameFramework.TileMap.Meshes.Json var reader = new StreamReader(file); var definition = JsonConvert.DeserializeObject(reader.ReadToEnd()); + reader.Dispose(); var collection = new TileMeshCollection(atlas);