diff --git a/src/Errors.h b/src/Errors.h index 25abd7206..45072a4b0 100644 --- a/src/Errors.h +++ b/src/Errors.h @@ -132,7 +132,8 @@ enum CC_ERRORS { HTTP_ERR_RELATIVE = 0xCCDED069UL, /* Unsupported relative URL format */ HTTP_ERR_INVALID_BODY= 0xCCDED06AUL, /* HTTP message doesn't have Content-Length or use Chunked transfer encoding */ HTTP_ERR_CHUNK_SIZE = 0xCCDED06BUL, /* HTTP message chunk has negative size/length */ - HTTP_ERR_TRUNCATED = 0xCCDED06CUL, /* HTTP respone header was truncated due to being too long */ + HTTP_ERR_TRUNCATED = 0xCCDED06CUL, /* HTTP response header was truncated due to being too long */ + HTTP_ERR_NO_RESPONSE = 0xCCDED06DUL, /* First attempt to read response returned 0 bytes */ SSL_ERR_CONTEXT_DEAD = 0xCCDED070UL, /* Server shutdown the SSL context and it must be recreated */ PNG_ERR_16BITSAMPLES = 0xCCDED071UL, /* Image uses 16 bit samples, which is unimplemented */ diff --git a/src/Graphics_3DS.c b/src/Graphics_3DS.c index 922636c76..422666a8e 100644 --- a/src/Graphics_3DS.c +++ b/src/Graphics_3DS.c @@ -806,7 +806,7 @@ void Gfx_CalcOrthoMatrix(struct Matrix* matrix, float width, float height, float matrix->row1.y = -2.0f / width; matrix->row4.y = 1.0f; - matrix->row3.z = 1.0f / (zNear - zFar); + matrix->row3.z = 1.0f / (zNear - zFar); matrix->row4.z = 0.5f * (zNear + zFar) / (zNear - zFar) - 0.5f; matrix->row4.w = 1.0f; } diff --git a/src/Http_Worker.c b/src/Http_Worker.c index 5bf547030..460db2716 100644 --- a/src/Http_Worker.c +++ b/src/Http_Worker.c @@ -558,6 +558,7 @@ static cc_result ConnectionPool_Open(struct HttpConnection** conn, const struct *--------------------------------------------------------HttpClient-------------------------------------------------------* *#########################################################################################################################*/ enum HTTP_RESPONSE_STATE { + HTTP_RESPONSE_STATE_INITIAL, HTTP_RESPONSE_STATE_HEADER, HTTP_RESPONSE_STATE_DATA, HTTP_RESPONSE_STATE_CHUNK_HEADER, @@ -583,7 +584,7 @@ struct HttpClientState { }; static void HttpClientState_Reset(struct HttpClientState* state) { - state->state = HTTP_RESPONSE_STATE_HEADER; + state->state = HTTP_RESPONSE_STATE_INITIAL; state->chunked = 0; state->dataLeft = 0; state->autoClose = false; @@ -705,6 +706,9 @@ static cc_result HttpClient_Process(struct HttpClientState* state, char* buffer, while (offset < total) { switch (state->state) { + case HTTP_RESPONSE_STATE_INITIAL: + state->state = HTTP_RESPONSE_STATE_HEADER; + break; case HTTP_RESPONSE_STATE_HEADER: { @@ -836,8 +840,8 @@ static cc_result HttpClient_ParseResponse(struct HttpClientState* state) { if (res) return res; if (total == 0) { - Platform_LogConst("Http read unexpectedly returned 0"); - return ERR_END_OF_STREAM; + Platform_Log1("Http read unexpectedly returned 0 in state %i", &state->state); + return state->state == HTTP_RESPONSE_STATE_INITIAL ? HTTP_ERR_NO_RESPONSE : ERR_END_OF_STREAM; } if (dst != buffer) { @@ -915,6 +919,11 @@ static cc_result HttpBackend_Do(struct HttpRequest* req, cc_string* urlStr) { res = HttpBackend_PerformRequest(&state); retried = true; } + if (res == HTTP_ERR_NO_RESPONSE && !retried) { + Platform_LogConst("Resetting connection due to empty response.."); + res = HttpBackend_PerformRequest(&state); + retried = true; + } if (res || !HttpClient_IsRedirect(req)) break; if (redirects >= 20) return HTTP_ERR_REDIRECTS; diff --git a/src/Vectors.c b/src/Vectors.c index 6ff297ab8..18c16b67f 100644 --- a/src/Vectors.c +++ b/src/Vectors.c @@ -210,36 +210,35 @@ cc_bool FrustumCulling_SphereInFrustum(float x, float y, float z, float radius) } void FrustumCulling_CalcFrustumEquations(struct Matrix* projection, struct Matrix* modelView) { - struct Matrix clipMatrix; - float* clip = (float*)&clipMatrix; - Matrix_Mul(&clipMatrix, modelView, projection); + struct Matrix clip; + Matrix_Mul(&clip, modelView, projection); - /* Extract the numbers for the RIGHT plane */ - frustum00 = clip[3] - clip[0]; - frustum01 = clip[7] - clip[4]; - frustum02 = clip[11] - clip[8]; - frustum03 = clip[15] - clip[12]; + /* Extract the RIGHT plane */ + frustum00 = clip.row1.w - clip.row1.x; + frustum01 = clip.row2.w - clip.row2.x; + frustum02 = clip.row3.w - clip.row3.x; + frustum03 = clip.row4.w - clip.row4.x; FrustumCulling_Normalise(&frustum00, &frustum01, &frustum02, &frustum03); - /* Extract the numbers for the LEFT plane */ - frustum10 = clip[3] + clip[0]; - frustum11 = clip[7] + clip[4]; - frustum12 = clip[11] + clip[8]; - frustum13 = clip[15] + clip[12]; + /* Extract the LEFT plane */ + frustum10 = clip.row1.w + clip.row1.x; + frustum11 = clip.row2.w + clip.row2.x; + frustum12 = clip.row3.w + clip.row3.x; + frustum13 = clip.row4.w + clip.row4.x; FrustumCulling_Normalise(&frustum10, &frustum11, &frustum12, &frustum13); /* Extract the BOTTOM plane */ - frustum20 = clip[3] + clip[1]; - frustum21 = clip[7] + clip[5]; - frustum22 = clip[11] + clip[9]; - frustum23 = clip[15] + clip[13]; + frustum20 = clip.row1.w + clip.row1.y; + frustum21 = clip.row2.w + clip.row2.y; + frustum22 = clip.row3.w + clip.row3.y; + frustum23 = clip.row4.w + clip.row4.y; FrustumCulling_Normalise(&frustum20, &frustum21, &frustum22, &frustum23); /* Extract the TOP plane */ - frustum30 = clip[3] - clip[1]; - frustum31 = clip[7] - clip[5]; - frustum32 = clip[11] - clip[9]; - frustum33 = clip[15] - clip[13]; + frustum30 = clip.row1.w - clip.row1.y; + frustum31 = clip.row2.w - clip.row2.y; + frustum32 = clip.row3.w - clip.row3.y; + frustum33 = clip.row4.w - clip.row4.y; FrustumCulling_Normalise(&frustum30, &frustum31, &frustum32, &frustum33); /* Extract the FAR plane (Different for each graphics backend) */ @@ -247,15 +246,15 @@ void FrustumCulling_CalcFrustumEquations(struct Matrix* projection, struct Matri /* OpenGL and Direct3D require slightly different behaviour for NEAR clipping planes */ /* https://www.gamedevs.org/uploads/fast-extraction-viewing-frustum-planes-from-world-view-projection-matrix.pdf */ /* (and because reverse Z is used, 'NEAR' plane is actually the 'FAR' clipping plane) */ - frustum40 = clip[2]; - frustum41 = clip[6]; - frustum42 = clip[10]; - frustum43 = clip[14]; + frustum40 = clip.row1.z; + frustum41 = clip.row2.z; + frustum42 = clip.row3.z; + frustum43 = clip.row4.z; #else - frustum40 = clip[3] - clip[2]; - frustum41 = clip[7] - clip[6]; - frustum42 = clip[11] - clip[10]; - frustum43 = clip[15] - clip[14]; + frustum40 = clip.row1.w - clip.row1.z; + frustum41 = clip.row2.w - clip.row2.z; + frustum42 = clip.row3.w - clip.row3.z; + frustum43 = clip.row4.w - clip.row4.z; #endif FrustumCulling_Normalise(&frustum40, &frustum41, &frustum42, &frustum43); }