mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 10:35:11 -04:00
Don't crash the game if socket() fails
Not that it every should anyways
This commit is contained in:
parent
15ca271e98
commit
e933ec2298
@ -17,7 +17,6 @@
|
||||
|
||||
int MapRenderer_ChunksX, MapRenderer_ChunksY, MapRenderer_ChunksZ;
|
||||
int MapRenderer_1DUsedCount, MapRenderer_ChunksCount;
|
||||
int MapRenderer_MaxUpdates;
|
||||
struct ChunkPartInfo* MapRenderer_PartsNormal;
|
||||
struct ChunkPartInfo* MapRenderer_PartsTranslucent;
|
||||
|
||||
@ -44,10 +43,8 @@ static struct ChunkInfo** renderChunks;
|
||||
static int renderChunksCount;
|
||||
/* Distance of each chunk from the camera. */
|
||||
static cc_uint32* distances;
|
||||
|
||||
/* Buffer for all chunk parts. There are (MapRenderer_ChunksCount * Atlas1D_Count) * 2 parts in the buffer,
|
||||
with parts for 'normal' buffer being in lower half. */
|
||||
static struct ChunkPartInfo* partsBuffer_Raw;
|
||||
/* Maximum number of chunk updates that can be performed in one frame. */
|
||||
static int maxChunkUpdates;
|
||||
|
||||
struct ChunkInfo* MapRenderer_GetChunk(int cx, int cy, int cz) {
|
||||
return &mapChunks[MapRenderer_Pack(cx, cy, cz)];
|
||||
@ -314,8 +311,7 @@ void MapRenderer_RenderTranslucent(double delta) {
|
||||
*----------------------------------------------------Chunks mangagement---------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static void FreeParts(void) {
|
||||
Mem_Free(partsBuffer_Raw);
|
||||
partsBuffer_Raw = NULL;
|
||||
Mem_Free(MapRenderer_PartsNormal);
|
||||
MapRenderer_PartsNormal = NULL;
|
||||
MapRenderer_PartsTranslucent = NULL;
|
||||
}
|
||||
@ -333,11 +329,12 @@ static void FreeChunks(void) {
|
||||
}
|
||||
|
||||
static void AllocateParts(void) {
|
||||
cc_uint32 count = MapRenderer_ChunksCount * MapRenderer_1DUsedCount;
|
||||
partsBuffer_Raw = (struct ChunkPartInfo*)Mem_AllocCleared(count * 2, sizeof(struct ChunkPartInfo), "chunk parts");
|
||||
struct ChunkPartInfo* ptr;
|
||||
cc_uint32 count = MapRenderer_ChunksCount * MapRenderer_1DUsedCount;
|
||||
|
||||
MapRenderer_PartsNormal = partsBuffer_Raw;
|
||||
MapRenderer_PartsTranslucent = partsBuffer_Raw + count;
|
||||
ptr = (struct ChunkPartInfo*)Mem_AllocCleared(count * 2, sizeof(struct ChunkPartInfo), "chunk parts");
|
||||
MapRenderer_PartsNormal = ptr;
|
||||
MapRenderer_PartsTranslucent = ptr + count;
|
||||
}
|
||||
|
||||
static void AllocateChunks(void) {
|
||||
@ -421,7 +418,8 @@ void MapRenderer_Refresh(void) {
|
||||
ResetPartCounts();
|
||||
}
|
||||
|
||||
void MapRenderer_RefreshBorders(int maxHeight) {
|
||||
/* Refreshes chunks on the border of the map whose y is less than 'maxHeight'. */
|
||||
static void RefreshBorderChunks(int maxHeight) {
|
||||
int cx, cy, cz;
|
||||
cc_bool onBorder;
|
||||
|
||||
@ -543,7 +541,7 @@ static void UpdateChunks(double delta) {
|
||||
|
||||
/* Build more chunks if 30 FPS or over, otherwise slowdown */
|
||||
chunksTarget += delta < CHUNK_TARGET_TIME ? 1 : -1;
|
||||
Math_Clamp(chunksTarget, 4, MapRenderer_MaxUpdates);
|
||||
Math_Clamp(chunksTarget, 4, maxChunkUpdates);
|
||||
|
||||
p = &LocalPlayer_Instance;
|
||||
samePos = Vec3_Equals(&Camera.CurrentPos, &lastCamPos)
|
||||
@ -717,7 +715,7 @@ static void OnEnvVariableChanged(void* obj, int envVar) {
|
||||
Builder_EdgeLevel = max(0, Env.EdgeHeight);
|
||||
|
||||
/* Only need to refresh chunks on map borders up to highest edge level.*/
|
||||
MapRenderer_RefreshBorders(max(oldClip, Builder_EdgeLevel));
|
||||
RefreshBorderChunks(max(oldClip, Builder_EdgeLevel));
|
||||
}
|
||||
}
|
||||
|
||||
@ -789,7 +787,7 @@ static void MapRenderer_Init(void) {
|
||||
/* This = 87 fixes map being invisible when no textures */
|
||||
MapRenderer_1DUsedCount = 87; /* Atlas1D_UsedAtlasesCount(); */
|
||||
chunkPos = IVec3_MaxValue();
|
||||
MapRenderer_MaxUpdates = Options_GetInt(OPT_MAX_CHUNK_UPDATES, 4, 1024, 30);
|
||||
maxChunkUpdates = Options_GetInt(OPT_MAX_CHUNK_UPDATES, 4, 1024, 30);
|
||||
CalcViewDists();
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,6 @@ extern int MapRenderer_ChunksX, MapRenderer_ChunksY, MapRenderer_ChunksZ;
|
||||
extern int MapRenderer_1DUsedCount;
|
||||
/* Number of chunks in the world, or ChunksX * ChunksY * ChunksZ */
|
||||
extern int MapRenderer_ChunksCount;
|
||||
/* Maximum number of chunk updates that can be performed in one frame. */
|
||||
extern int MapRenderer_MaxUpdates;
|
||||
|
||||
/* Buffer for all chunk parts. There are (MapRenderer_ChunksCount * Atlas1D_Count) parts in the buffer,
|
||||
with parts for 'normal' buffer being in lower half. */
|
||||
@ -89,9 +87,6 @@ void MapRenderer_DeleteChunk(struct ChunkInfo* info);
|
||||
/* NOTE: This method also adjusts internal state, so do not bypass this. */
|
||||
void MapRenderer_BuildChunk(struct ChunkInfo* info, int* chunkUpdates);
|
||||
|
||||
/* Refreshes chunks on the border of the map. */
|
||||
/* NOTE: Only refreshes border chunks whose y is less than 'maxHeight'. */
|
||||
void MapRenderer_RefreshBorders(int maxHeight);
|
||||
/* Deletes all chunks and resets internal state. */
|
||||
void MapRenderer_Refresh(void);
|
||||
#endif
|
||||
|
@ -861,11 +861,9 @@ void Platform_LoadSysFonts(void) {
|
||||
/*########################################################################################################################*
|
||||
*---------------------------------------------------------Socket----------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
void Socket_Create(SocketHandle* socketResult) {
|
||||
cc_result Socket_Create(SocketHandle* socketResult) {
|
||||
*socketResult = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (*socketResult == -1) {
|
||||
Logger_Abort2(Socket__Error(), "Failed to create socket");
|
||||
}
|
||||
return *socketResult == -1 ? Socket__Error() : 0;
|
||||
}
|
||||
|
||||
static cc_result Socket_ioctl(SocketHandle socket, cc_uint32 cmd, int* data) {
|
||||
|
@ -193,7 +193,7 @@ CC_API void Waitable_WaitFor(void* handle, cc_uint32 milliseconds);
|
||||
void Platform_LoadSysFonts(void);
|
||||
|
||||
/* Allocates a new socket. */
|
||||
CC_API void Socket_Create(SocketHandle* socket);
|
||||
CC_API cc_result Socket_Create(SocketHandle* socket);
|
||||
/* Returns how much data is available to be read from the given socket. */
|
||||
CC_API cc_result Socket_Available(SocketHandle socket, cc_uint32* available);
|
||||
/* Sets whether operations on the given socket block the calling thread. */
|
||||
|
@ -301,7 +301,8 @@ static void MPConnection_BeginConnect(void) {
|
||||
cc_result res;
|
||||
String_InitArray(title, titleBuffer);
|
||||
|
||||
Socket_Create(&net_socket);
|
||||
res = Socket_Create(&net_socket);
|
||||
if (res) { MPConnection_FailConnect(res); return; }
|
||||
Server.Disconnected = false;
|
||||
|
||||
Socket_SetBlocking(net_socket, false);
|
||||
|
Loading…
x
Reference in New Issue
Block a user