From ab2a86a195793456a87be5b29b8ca87f5abe2726 Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Fri, 27 Oct 2017 14:06:15 -0400 Subject: [PATCH] Crash fix for #268 --- TrueCraft.Client/Handlers/ChunkHandlers.cs | 25 +++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/TrueCraft.Client/Handlers/ChunkHandlers.cs b/TrueCraft.Client/Handlers/ChunkHandlers.cs index 042892f..6698c5b 100644 --- a/TrueCraft.Client/Handlers/ChunkHandlers.cs +++ b/TrueCraft.Client/Handlers/ChunkHandlers.cs @@ -52,16 +52,31 @@ namespace TrueCraft.Client.Handlers && packet.Height == Chunk.Height && packet.Depth == Chunk.Depth) // Fast path { + // Chunk data offsets + int metadataOffset = chunk.Data.Length; + int lightOffset = metadataOffset + chunk.Metadata.Length; + int skylightOffset = lightOffset + chunk.BlockLight.Length; + // Block IDs Buffer.BlockCopy(data, 0, chunk.Data, 0, chunk.Data.Length); // Block metadata - Buffer.BlockCopy(data, chunk.Data.Length, chunk.Metadata.Data, 0, chunk.Metadata.Data.Length); + if (metadataOffset < data.Length) + { + Buffer.BlockCopy(data, metadataOffset, + chunk.Metadata.Data, 0, chunk.Metadata.Data.Length); + } // Block light - Buffer.BlockCopy(data, chunk.Data.Length + chunk.Metadata.Data.Length, - chunk.BlockLight.Data, 0, chunk.BlockLight.Data.Length); + if (lightOffset < data.Length) + { + Buffer.BlockCopy(data, lightOffset, + chunk.BlockLight.Data, 0, chunk.BlockLight.Data.Length); + } // Sky light - Buffer.BlockCopy(data, chunk.Data.Length + chunk.Metadata.Data.Length + chunk.BlockLight.Data.Length, - chunk.SkyLight.Data, 0, chunk.SkyLight.Data.Length); + if (skylightOffset < data.Length) + { + Buffer.BlockCopy(data, skylightOffset, + chunk.SkyLight.Data, 0, chunk.SkyLight.Data.Length); + } } else // Slow path {