mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 02:56:09 -04:00
Fix crashing if map fails to generate
This commit is contained in:
parent
035f5cedd8
commit
cff7c6cd1b
@ -74,8 +74,6 @@ void Map_LoadFrom(const String* path) {
|
|||||||
if (res) { Logger_Warn2(res, "closing", path); }
|
if (res) { Logger_Warn2(res, "closing", path); }
|
||||||
|
|
||||||
World_SetNewMap(World.Blocks, World.Width, World.Height, World.Length);
|
World_SetNewMap(World.Blocks, World.Width, World.Height, World.Length);
|
||||||
Event_RaiseVoid(&WorldEvents.MapLoaded);
|
|
||||||
|
|
||||||
LocationUpdate_MakePosAndOri(&update, p->Spawn, p->SpawnYaw, p->SpawnPitch, false);
|
LocationUpdate_MakePosAndOri(&update, p->Spawn, p->SpawnYaw, p->SpawnPitch, false);
|
||||||
p->Base.VTABLE->SetLocation(&p->Base, &update, false);
|
p->Base.VTABLE->SetLocation(&p->Base, &update, false);
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,6 @@ void* Mem_Realloc(void* mem, cc_uint32 numElems, cc_uint32 elemsSize, const char
|
|||||||
#if defined CC_BUILD_WIN
|
#if defined CC_BUILD_WIN
|
||||||
void* Mem_TryAlloc(cc_uint32 numElems, cc_uint32 elemsSize) {
|
void* Mem_TryAlloc(cc_uint32 numElems, cc_uint32 elemsSize) {
|
||||||
cc_uint32 numBytes = numElems * elemsSize; /* TODO: avoid overflow here */
|
cc_uint32 numBytes = numElems * elemsSize; /* TODO: avoid overflow here */
|
||||||
if (numBytes >= 128 * 64 * 128) return NULL;
|
|
||||||
return HeapAlloc(heap, 0, numBytes);
|
return HeapAlloc(heap, 0, numBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -528,20 +528,12 @@ static void Classic_LevelFinalise(cc_uint8* data) {
|
|||||||
Chat_AddRaw(" &cBlocks array size does not match volume of map");
|
Chat_AddRaw(" &cBlocks array size does not match volume of map");
|
||||||
FreeMapStates();
|
FreeMapStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: TEMP HACK */
|
|
||||||
if (!map.blocks) {
|
|
||||||
width = 0; height = 0; length = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
World_SetNewMap(map.blocks, width, height, length);
|
|
||||||
#ifdef EXTENDED_BLOCKS
|
#ifdef EXTENDED_BLOCKS
|
||||||
/* defer allocation of second map array if possible */
|
/* defer allocation of second map array if possible */
|
||||||
if (cpe_extBlocks && map2.blocks) {
|
if (cpe_extBlocks && map2.blocks) World_SetMapUpper(map2.blocks);
|
||||||
World_SetMapUpper(map2.blocks);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
Event_RaiseVoid(&WorldEvents.MapLoaded);
|
World_SetNewMap(map.blocks, width, height, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Classic_SetBlock(cc_uint8* data) {
|
static void Classic_SetBlock(cc_uint8* data) {
|
||||||
|
@ -1366,8 +1366,8 @@ static void GeneratingScreen_EndGeneration(void) {
|
|||||||
Gui_Remove((struct Screen*)&LoadingScreen);
|
Gui_Remove((struct Screen*)&LoadingScreen);
|
||||||
Gen_Done = false;
|
Gen_Done = false;
|
||||||
|
|
||||||
if (!Gen_Blocks) { Chat_AddRaw("&cFailed to generate the map."); return; }
|
|
||||||
World_SetNewMap(Gen_Blocks, World.Width, World.Height, World.Length);
|
World_SetNewMap(Gen_Blocks, World.Width, World.Height, World.Length);
|
||||||
|
if (!Gen_Blocks) { Chat_AddRaw("&cFailed to generate the map."); return; }
|
||||||
Gen_Blocks = NULL;
|
Gen_Blocks = NULL;
|
||||||
|
|
||||||
x = (World.Width / 2) + 0.5f; z = (World.Length / 2) + 0.5f;
|
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);
|
LocationUpdate_MakePosAndOri(&update, p->Spawn, 0.0f, 0.0f, false);
|
||||||
p->Base.VTABLE->SetLocation(&p->Base, &update, false);
|
p->Base.VTABLE->SetLocation(&p->Base, &update, false);
|
||||||
|
/* TODO: This needs to be before new map... */
|
||||||
Camera.CurrentPos = Camera.Active->GetPosition(0.0f);
|
Camera.CurrentPos = Camera.Active->GetPosition(0.0f);
|
||||||
Event_RaiseVoid(&WorldEvents.MapLoaded);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GeneratingScreen_Render(void* screen, double delta) {
|
static void GeneratingScreen_Render(void* screen, double delta) {
|
||||||
|
@ -56,6 +56,9 @@ void World_NewMap(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void World_SetNewMap(BlockRaw* blocks, int width, int height, int length) {
|
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_SetDimensions(width, height, length);
|
||||||
World.Blocks = blocks;
|
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.EdgeHeight == -1) { Env.EdgeHeight = height / 2; }
|
||||||
if (Env.CloudsHeight == -1) { Env.CloudsHeight = height + 2; }
|
if (Env.CloudsHeight == -1) { Env.CloudsHeight = height + 2; }
|
||||||
|
|
||||||
GenerateNewUuid();
|
GenerateNewUuid();
|
||||||
World.Loaded = true;
|
World.Loaded = true;
|
||||||
|
Event_RaiseVoid(&WorldEvents.MapLoaded);
|
||||||
}
|
}
|
||||||
|
|
||||||
CC_NOINLINE void World_SetDimensions(int width, int height, int length) {
|
CC_NOINLINE void World_SetDimensions(int width, int height, int length) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user