diff --git a/include/openspace/engine/downloadmanager.h b/include/openspace/engine/downloadmanager.h index 2e6831767d..a3c6e10527 100644 --- a/include/openspace/engine/downloadmanager.h +++ b/include/openspace/engine/downloadmanager.h @@ -64,6 +64,7 @@ public: struct MemoryFile { std::string buffer; std::string format; + bool corrupted; }; using DownloadProgressCallback = std::function; diff --git a/modules/iswa/rendering/dataplane.cpp b/modules/iswa/rendering/dataplane.cpp index ff16f9076a..2c1a572667 100644 --- a/modules/iswa/rendering/dataplane.cpp +++ b/modules/iswa/rendering/dataplane.cpp @@ -95,15 +95,15 @@ DataPlane::~DataPlane(){} bool DataPlane::loadTexture() { + // if The future is done then get the new dataFile if(_futureObject.valid() && DownloadManager::futureReady(_futureObject)){ - try { - _dataFile = _futureObject.get(); - } catch( std::exception& e ) { - LWARNING( "DataPlane future data exception: " + std::string(e.what()) ); + _dataFile = _futureObject.get(); + + if(_dataFile.corrupted) return false; - } } + // if the buffer in the datafile is empty, do not proceed if(_dataFile.buffer.empty()) return false; diff --git a/modules/iswa/rendering/screenspacecygnet.cpp b/modules/iswa/rendering/screenspacecygnet.cpp index 11ca7cff5a..1d06e0968f 100644 --- a/modules/iswa/rendering/screenspacecygnet.cpp +++ b/modules/iswa/rendering/screenspacecygnet.cpp @@ -134,26 +134,24 @@ void ScreenSpaceCygnet::updateTexture(){ void ScreenSpaceCygnet::loadTexture() { - try { + DownloadManager::MemoryFile imageFile = _futureImage.get(); - DownloadManager::MemoryFile imageFile = _futureImage.get(); - std::unique_ptr texture = ghoul::io::TextureReader::ref().loadTexture( - (void*) imageFile.buffer.c_str(), - imageFile.buffer.size(), - imageFile.format); + if(imageFile.corrupted) + return; - if (texture) { - LDEBUG("Loaded texture from iswa cygnet with id: '" << _cygnetId << "'"); + std::unique_ptr texture = ghoul::io::TextureReader::ref().loadTexture( + (void*) imageFile.buffer.c_str(), + imageFile.buffer.size(), + imageFile.format); - texture->uploadTexture(); - // Textures of planets looks much smoother with AnisotropicMipMap rather than linear - texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); + if (texture) { + LDEBUG("Loaded texture from iswa cygnet with id: '" << _cygnetId << "'"); - _texture = std::move(texture); - } + texture->uploadTexture(); + // Textures of planets looks much smoother with AnisotropicMipMap rather than linear + texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); - } catch( std::exception& e ) { - LWARNING( "ScreenSpaceCygnet futureImage exception: " + std::string(e.what()) ); + _texture = std::move(texture); } } } \ No newline at end of file diff --git a/modules/iswa/rendering/textureplane.cpp b/modules/iswa/rendering/textureplane.cpp index b6bce01261..6d06350d6b 100644 --- a/modules/iswa/rendering/textureplane.cpp +++ b/modules/iswa/rendering/textureplane.cpp @@ -56,13 +56,10 @@ TexturePlane::~TexturePlane(){} bool TexturePlane::loadTexture() { - DownloadManager::MemoryFile imageFile; - try { - imageFile = _futureObject.get(); - } catch( std::exception& e ) { - LWARNING( "Textureplane futureImage exception: " + std::string(e.what()) ); + DownloadManager::MemoryFile imageFile = _futureObject.get(); + + if(imageFile.corrupted) return false; - } std::unique_ptr texture = ghoul::io::TextureReader::ref().loadTexture( (void*) imageFile.buffer.c_str(), diff --git a/modules/iswa/util/iswamanager.cpp b/modules/iswa/util/iswamanager.cpp index 7351803c53..ecad85bba0 100644 --- a/modules/iswa/util/iswamanager.cpp +++ b/modules/iswa/util/iswamanager.cpp @@ -203,10 +203,10 @@ std::future ISWAManager::fetchImageCygnet(int id){ return std::move( DlManager.fetchFile( iSWAurl(id, "image"), [id](const DownloadManager::MemoryFile& file){ - LDEBUG("Download to memory finished"); + LDEBUG("Download to memory finished for image cygnet with id: " + std::to_string(id)); }, [id](const std::string& err){ - LDEBUG("Download to memory was aborted: " + err); + LDEBUG("Download to memory was aborted for image cygnet with id "+ std::to_string(id)+": " + err); } ) ); } diff --git a/src/engine/downloadmanager.cpp b/src/engine/downloadmanager.cpp index b0cda1ed15..21124ce57b 100644 --- a/src/engine/downloadmanager.cpp +++ b/src/engine/downloadmanager.cpp @@ -294,15 +294,19 @@ std::future DownloadManager::fetchFile( } successCallback(file); curl_easy_cleanup(curl); + file.corrupted = false; return std::move(file); } else { std::string err = curl_easy_strerror(res); errorCallback(err); curl_easy_cleanup(curl); // Throw an error and use try-catch around future.get() call - throw std::runtime_error( err ); + //throw std::runtime_error( err ); + // or set a boolean variable in MemoryFile to determine if it is valid/corrupted or not. // Return MemoryFile even if it is not valid, and check if it is after future.get() call. + file.corrupted = true; + return std::move(file); } } };