C client: Fix game crashing when starting in advanced lighting mode

This commit is contained in:
UnknownShadow200 2018-09-19 13:16:53 +10:00
parent 9ac3e5c302
commit 74dbfffd44
3 changed files with 12 additions and 10 deletions

View file

@ -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

View file

@ -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;

View file

@ -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 */