diff --git a/src/https.cpp b/src/https.cpp index 6d9bb2050..2d2d82062 100644 --- a/src/https.cpp +++ b/src/https.cpp @@ -51,10 +51,12 @@ EM_JS(void, em_https_request, (const char* type, const char* url, const char* bo Module._free(response_buffer); } else { console.log('The request failed: ' + xhr.status + ' ' + xhr.statusText); + Module.ccall('em_https_request_callback_wrapper', 'void', ['number', 'number', 'number'], [callback, 0, 0]); } }; xhr.onerror = function() { console.log('The request failed!'); + Module.ccall('em_https_request_callback_wrapper', 'void', ['number', 'number', 'number'], [callback, 0, 0]); }; xhr.send(body_arr); }); @@ -62,7 +64,13 @@ EM_JS(void, em_https_request, (const char* type, const char* url, const char* bo extern "C" void em_https_request_callback_wrapper(void* callback, void* data, int size) { - std::vector result((uint8_t*)data, (uint8_t*)data + (size_t)size); + std::vector result; + + if (size != 0) + { + result = std::vector((uint8_t*)data, (uint8_t*)data + (size_t)size); + } + std::function&)>* fcallback = (std::function&)>*)callback; (*fcallback)(result); diff --git a/src/retro_achievements.cpp b/src/retro_achievements.cpp index cb3a98c2d..cfbe914a7 100644 --- a/src/retro_achievements.cpp +++ b/src/retro_achievements.cpp @@ -828,6 +828,13 @@ void ra_state_t::download(ra_game_state_ptr game_state, const std::string& url, // The image is not already downloaded, let's download it https_request(http_request_e::GET, url, {}, {}, [url, game_state, callback](const std::vector& result) { + if (result.empty()) + { + printf("[rcheevos]: empty response from: %s\n", url.c_str()); + game_state->dec(); + return; + } + rc_api_server_response_t response; response.body = (const char*)result.data(); response.body_length = result.size();