Fix crashing if map fails to generate

This commit is contained in:
UnknownShadow200 2020-03-31 19:07:54 +11:00
parent 035f5cedd8
commit cff7c6cd1b
5 changed files with 10 additions and 17 deletions

View File

@ -74,8 +74,6 @@ void Map_LoadFrom(const String* path) {
if (res) { Logger_Warn2(res, "closing", path); }
World_SetNewMap(World.Blocks, World.Width, World.Height, World.Length);
Event_RaiseVoid(&WorldEvents.MapLoaded);
LocationUpdate_MakePosAndOri(&update, p->Spawn, p->SpawnYaw, p->SpawnPitch, false);
p->Base.VTABLE->SetLocation(&p->Base, &update, false);
}

View File

@ -135,7 +135,6 @@ void* Mem_Realloc(void* mem, cc_uint32 numElems, cc_uint32 elemsSize, const char
#if defined CC_BUILD_WIN
void* Mem_TryAlloc(cc_uint32 numElems, cc_uint32 elemsSize) {
cc_uint32 numBytes = numElems * elemsSize; /* TODO: avoid overflow here */
if (numBytes >= 128 * 64 * 128) return NULL;
return HeapAlloc(heap, 0, numBytes);
}

View File

@ -528,20 +528,12 @@ static void Classic_LevelFinalise(cc_uint8* data) {
Chat_AddRaw(" &cBlocks array size does not match volume of map");
FreeMapStates();
}
/* TODO: TEMP HACK */
if (!map.blocks) {
width = 0; height = 0; length = 0;
}
World_SetNewMap(map.blocks, width, height, length);
#ifdef EXTENDED_BLOCKS
/* defer allocation of second map array if possible */
if (cpe_extBlocks && map2.blocks) {
World_SetMapUpper(map2.blocks);
}
if (cpe_extBlocks && map2.blocks) World_SetMapUpper(map2.blocks);
#endif
Event_RaiseVoid(&WorldEvents.MapLoaded);
World_SetNewMap(map.blocks, width, height, length);
}
static void Classic_SetBlock(cc_uint8* data) {

View File

@ -1366,8 +1366,8 @@ static void GeneratingScreen_EndGeneration(void) {
Gui_Remove((struct Screen*)&LoadingScreen);
Gen_Done = false;
if (!Gen_Blocks) { Chat_AddRaw("&cFailed to generate the map."); return; }
World_SetNewMap(Gen_Blocks, World.Width, World.Height, World.Length);
if (!Gen_Blocks) { Chat_AddRaw("&cFailed to generate the map."); return; }
Gen_Blocks = NULL;
x = (World.Width / 2) + 0.5f; z = (World.Length / 2) + 0.5f;
@ -1375,9 +1375,8 @@ static void GeneratingScreen_EndGeneration(void) {
LocationUpdate_MakePosAndOri(&update, p->Spawn, 0.0f, 0.0f, false);
p->Base.VTABLE->SetLocation(&p->Base, &update, false);
/* TODO: This needs to be before new map... */
Camera.CurrentPos = Camera.Active->GetPosition(0.0f);
Event_RaiseVoid(&WorldEvents.MapLoaded);
}
static void GeneratingScreen_Render(void* screen, double delta) {

View File

@ -56,6 +56,9 @@ void World_NewMap(void) {
}
void World_SetNewMap(BlockRaw* blocks, int width, int height, int length) {
/* TODO: TEMP HACK */
if (!blocks) { width = 0; height = 0; length = 0; }
World_SetDimensions(width, height, length);
World.Blocks = blocks;
@ -70,8 +73,10 @@ void World_SetNewMap(BlockRaw* blocks, int width, int height, int length) {
if (Env.EdgeHeight == -1) { Env.EdgeHeight = height / 2; }
if (Env.CloudsHeight == -1) { Env.CloudsHeight = height + 2; }
GenerateNewUuid();
World.Loaded = true;
Event_RaiseVoid(&WorldEvents.MapLoaded);
}
CC_NOINLINE void World_SetDimensions(int width, int height, int length) {