diff --git a/ClassicalSharp/MeshBuilder/Builder.cs b/ClassicalSharp/MeshBuilder/Builder.cs index 7861362d1..f21c3469a 100644 --- a/ClassicalSharp/MeshBuilder/Builder.cs +++ b/ClassicalSharp/MeshBuilder/Builder.cs @@ -37,13 +37,13 @@ namespace ClassicalSharp { protected VertexP3fT2fC4b[] vertices; bool BuildChunk(int x1, int y1, int z1, ref bool allAir) { - light = game.Lighting; - PreStretchTiles(x1, y1, z1); + light = game.Lighting; BlockID* chunkPtr = stackalloc BlockID[extChunkSize3]; chunk = chunkPtr; byte* countsPtr = stackalloc byte[chunkSize3 * Side.Sides]; counts = countsPtr; int* bitsPtr = stackalloc int[extChunkSize3]; bitFlags = bitsPtr; - MemUtils.memset((IntPtr)chunkPtr, 0, 0, extChunkSize3 * sizeof(BlockID)); + PreStretchTiles(x1, y1, z1); + MemUtils.memset((IntPtr)chunkPtr, 0, 0, extChunkSize3 * sizeof(BlockID)); bool allSolid = false; fixed (BlockRaw* mapPtr = map.blocks) { #if !ONLY_8BIT diff --git a/src/Builder.c b/src/Builder.c index 5400e8ab0..ac2cdbdfa 100644 --- a/src/Builder.c +++ b/src/Builder.c @@ -270,10 +270,10 @@ static void Builder_ReadChunkData(Int32 x1, Int32 y1, Int32 z1, bool* outAllAir, } static bool Builder_BuildChunk(Int32 x1, Int32 y1, Int32 z1, bool* allAir) { - Builder_PreStretchTiles(x1, y1, z1); BlockID chunk[EXTCHUNK_SIZE_3]; Builder_Chunk = chunk; UInt8 counts[CHUNK_SIZE_3 * FACE_COUNT]; Builder_Counts = counts; Int32 bitFlags[EXTCHUNK_SIZE_3]; Builder_BitFlags = bitFlags; + Builder_PreStretchTiles(x1, y1, z1); Mem_Set(chunk, BLOCK_AIR, EXTCHUNK_SIZE_3 * sizeof(BlockID)); bool allSolid; diff --git a/src/Platform.c b/src/Platform.c index d501255b2..2e808b1cc 100644 --- a/src/Platform.c +++ b/src/Platform.c @@ -81,16 +81,18 @@ ReturnCode ReturnCode_SocketWouldBlock = EWOULDBLOCK; /*########################################################################################################################* *---------------------------------------------------------Memory----------------------------------------------------------* *#########################################################################################################################*/ -static void Platform_AllocFailed(const char* place) { - char logBuffer[STRING_SIZE + 20] = { 0 }; - String log = String_FromArray(logBuffer); +void Mem_Set(void* dst, UInt8 value, UInt32 numBytes) { memset(dst, value, numBytes); } +void Mem_Copy(void* dst, void* src, UInt32 numBytes) { memcpy(dst, src, numBytes); } + +NOINLINE_ static void Platform_AllocFailed(const char* place) { + char logBuffer[STRING_SIZE+20 + 1]; + String log = String_NT_Array(logBuffer); String_Format1(&log, "Failed allocating memory for: %c", place); + + log.buffer[log.length] = '\0'; ErrorHandler_Fail(log.buffer); } -void Mem_Set(void* dst, UInt8 value, UInt32 numBytes) { memset(dst, value, numBytes); } -void Mem_Copy(void* dst, void* src, UInt32 numBytes) { memcpy(dst, src, numBytes); } - #if CC_BUILD_WIN void* Mem_Alloc(UInt32 numElems, UInt32 elemsSize, const char* place) { UInt32 numBytes = numElems * elemsSize; /* TODO: avoid overflow here */