mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-24 21:39:02 -05:00
remove thrown exception from fetchFile and replaced with corrupted flag in returned MemoryFile
This commit is contained in:
@@ -64,6 +64,7 @@ public:
|
||||
struct MemoryFile {
|
||||
std::string buffer;
|
||||
std::string format;
|
||||
bool corrupted;
|
||||
};
|
||||
|
||||
using DownloadProgressCallback = std::function<void(const FileFuture&)>;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -134,26 +134,24 @@ void ScreenSpaceCygnet::updateTexture(){
|
||||
|
||||
void ScreenSpaceCygnet::loadTexture() {
|
||||
|
||||
try {
|
||||
DownloadManager::MemoryFile imageFile = _futureImage.get();
|
||||
|
||||
DownloadManager::MemoryFile imageFile = _futureImage.get();
|
||||
std::unique_ptr<ghoul::opengl::Texture> 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<ghoul::opengl::Texture> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<ghoul::opengl::Texture> texture = ghoul::io::TextureReader::ref().loadTexture(
|
||||
(void*) imageFile.buffer.c_str(),
|
||||
|
||||
@@ -203,10 +203,10 @@ std::future<DownloadManager::MemoryFile> 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);
|
||||
}
|
||||
) );
|
||||
}
|
||||
|
||||
@@ -294,15 +294,19 @@ std::future<DownloadManager::MemoryFile> 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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user