diff --git a/TrueCraft.API/ItemStack.cs b/TrueCraft.API/ItemStack.cs index 6921d34..d6e0f44 100644 --- a/TrueCraft.API/ItemStack.cs +++ b/TrueCraft.API/ItemStack.cs @@ -252,11 +252,14 @@ namespace TrueCraft.API { if (Empty) return "(Empty)"; - string result = "ID: " + ID; - if (Count != 1) result += "; Count: " + Count; - if (Metadata != 0) result += "; Metadata: " + Metadata; - if (Nbt != null) result += Environment.NewLine + Nbt.ToString(); - return "(" + result + ")"; + + StringBuilder resultBuilder = new StringBuilder("ID: " + ID); + + if (Count != 1) resultBuilder.Append("; Count: " + Count); + if (Metadata != 0) resultBuilder.Append("; Metadata: " + Metadata); + if (Nbt != null) resultBuilder.Append(Environment.NewLine + Nbt.ToString()); + + return "(" + resultBuilder.ToString() + ")"; } /// diff --git a/TrueCraft.API/Ray.cs b/TrueCraft.API/Ray.cs index dbd3e57..2da021e 100644 --- a/TrueCraft.API/Ray.cs +++ b/TrueCraft.API/Ray.cs @@ -94,18 +94,29 @@ namespace TrueCraft.API Vector3 maxT = new Vector3(-1.0f); //Vector3 minT = new Vector3(-1.0f); //calcul intersection with each faces - if (Position.X < box.Min.X && Direction.X != 0.0f) - maxT.X = (box.Min.X - Position.X) / Direction.X; - else if (Position.X > box.Max.X && Direction.X != 0.0f) - maxT.X = (box.Max.X - Position.X) / Direction.X; - if (Position.Y < box.Min.Y && Direction.Y != 0.0f) - maxT.Y = (box.Min.Y - Position.Y) / Direction.Y; - else if (Position.Y > box.Max.Y && Direction.Y != 0.0f) - maxT.Y = (box.Max.Y - Position.Y) / Direction.Y; - if (Position.Z < box.Min.Z && Direction.Z != 0.0f) - maxT.Z = (box.Min.Z - Position.Z) / Direction.Z; - else if (Position.Z > box.Max.Z && Direction.Z != 0.0f) - maxT.Z = (box.Max.Z - Position.Z) / Direction.Z; + if (Direction.X != 0.0f) + { + if (Position.X < box.Min.X) + maxT.X = (box.Min.X - Position.X) / Direction.X; + else if (Position.X > box.Max.X) + maxT.X = (box.Max.X - Position.X) / Direction.X; + } + + if (Direction.Y != 0.0f) + { + if (Position.Y < box.Min.Y) + maxT.Y = (box.Min.Y - Position.Y) / Direction.Y; + else if (Position.Y > box.Max.Y) + maxT.Y = (box.Max.Y - Position.Y) / Direction.Y; + } + + if (Direction.Z != 0.0f) + { + if (Position.Z < box.Min.Z) + maxT.Z = (box.Min.Z - Position.Z) / Direction.Z; + else if (Position.Z > box.Max.Z) + maxT.Z = (box.Max.Z - Position.Z) / Direction.Z; + } //get the maximum maxT if (maxT.X > maxT.Y && maxT.X > maxT.Z) diff --git a/TrueCraft.Client/Rendering/Font.cs b/TrueCraft.Client/Rendering/Font.cs index 9900c8e..0e48441 100644 --- a/TrueCraft.Client/Rendering/Font.cs +++ b/TrueCraft.Client/Rendering/Font.cs @@ -73,6 +73,14 @@ namespace TrueCraft.Client.Rendering using (var contents = File.OpenRead(Path.Combine(contentManager.RootDirectory, definitionPath))) _definition = FontLoader.Load(contents); + if (_textures != null) + { + for (int i = 0; i < _textures.Length; i++) + { + _textures[i].Dispose(); + } + } + // We need to support multiple texture pages for more than plain ASCII text. _textures = new Texture2D[_definition.Pages.Count]; for (int i = 0; i < _definition.Pages.Count; i++) diff --git a/TrueCraft.Client/Rendering/TextureMapper.cs b/TrueCraft.Client/Rendering/TextureMapper.cs index 29d4c79..0e0486c 100644 --- a/TrueCraft.Client/Rendering/TextureMapper.cs +++ b/TrueCraft.Client/Rendering/TextureMapper.cs @@ -101,11 +101,12 @@ namespace TrueCraft.Client.Rendering { try { - var ms = new MemoryStream(); - CopyStream(stream, ms); - ms.Seek(0, SeekOrigin.Begin); - AddTexture(key, new PngReader().Read(ms, Device)); - ms.Dispose(); + using (var ms = new MemoryStream()) + { + CopyStream(stream, ms); + ms.Seek(0, SeekOrigin.Begin); + AddTexture(key, new PngReader().Read(ms, Device)); + } } catch (Exception ex) { Console.WriteLine("Exception occured while loading {0} from texture pack:\n\n{1}", key, ex); } } @@ -184,7 +185,6 @@ namespace TrueCraft.Client.Rendering foreach (var pair in Customs) pair.Value.Dispose(); - Customs.Clear(); Customs = null; Device = null; IsDisposed = true;