diff --git a/Sledge.DataStructures/Models/Model.cs b/Sledge.DataStructures/Models/Model.cs index 501bb2aa8..3819ca98e 100644 --- a/Sledge.DataStructures/Models/Model.cs +++ b/Sledge.DataStructures/Models/Model.cs @@ -82,6 +82,7 @@ public void PreprocessModel() /// private void CombineTextures() { + if (!Textures.Any()) return; // Calculate the dimension of the combined texture var width = 0; var height = 0; diff --git a/Sledge.FileSystem/PakFile.cs b/Sledge.FileSystem/PakFile.cs index 19e5ea06a..bb0718fd9 100644 --- a/Sledge.FileSystem/PakFile.cs +++ b/Sledge.FileSystem/PakFile.cs @@ -351,6 +351,7 @@ protected override void Dispose(bool disposing) _stream.Dispose(); _package.Dispose(); HLLib.Shutdown(); + _open = false; } base.Dispose(disposing); } diff --git a/Sledge.Libs/HLLib/HLLib.cs b/Sledge.Libs/HLLib/HLLib.cs index 1aef77df1..897789cea 100644 --- a/Sledge.Libs/HLLib/HLLib.cs +++ b/Sledge.Libs/HLLib/HLLib.cs @@ -858,10 +858,13 @@ public byte[] Read(uint size) return buffer; } - public override void Close() + private bool _disposed = false; + protected override void Dispose(bool disposing) { - if (!IsOpened) return; + if (_disposed || !IsOpened) return; + _disposed = true; Close(StreamPtr); + base.Dispose(disposing); } public override long Seek(long offset, SeekOrigin origin) @@ -902,7 +905,7 @@ public override long Length public override long Position { - get { return Pointer; } + get { return GetStreamPointer(StreamPtr); } set { Seek(value, SeekMode.Beginning); } } diff --git a/Sledge.Providers/Model/MdlProvider.cs b/Sledge.Providers/Model/MdlProvider.cs index 9022f4aee..6d6e6edfa 100644 --- a/Sledge.Providers/Model/MdlProvider.cs +++ b/Sledge.Providers/Model/MdlProvider.cs @@ -47,7 +47,7 @@ protected override DataStructures.Models.Model LoadFromFile(IFile file) // Model loader for MDL files. Reference Valve's studiohdr_t struct definition for the most part. public DataStructures.Models.Model LoadMDL(IFile file, ModelLoadItems loadItems) { - using (var fs = file.Open()) + using (var fs = new MemoryStream(file.ReadAll())) { using(var br = new BinaryReader(fs)) { @@ -341,8 +341,10 @@ private static void ReadTextureInfo(IFile file, BinaryReader br, ModelData data, if (data.Version == MDLVersionGoldsource) { var tempBr = br; + var disp = false; if (numTextures == 0) { + disp = true; var texFile = file.Parent.GetFile(file.NameWithoutExtension + "T." + file.Extension); br = new BinaryReader(texFile.Open()); br.BaseStream.Position = 180; // skip all the unused nonsense in the T file @@ -393,7 +395,7 @@ private static void ReadTextureInfo(IFile file, BinaryReader br, ModelData data, br.BaseStream.Position = savedPosition; } // - if (numTextures == 0) + if (disp) { br.BaseStream.Dispose(); br.Dispose();