From e227008331cbb05aa7e0d2842e74812f816361da Mon Sep 17 00:00:00 2001 From: Richard Harrison Date: Wed, 20 Feb 2019 19:00:02 +0100 Subject: [PATCH] DDS-TC handle sgio_exceptions during hash creation. ref: https://sourceforge.net/p/flightgear/codetickets/2113/ --- simgear/scene/model/ModelRegistry.cxx | 41 ++++++++++++++++----------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/simgear/scene/model/ModelRegistry.cxx b/simgear/scene/model/ModelRegistry.cxx index ca2beb1f..6b18d5a3 100644 --- a/simgear/scene/model/ModelRegistry.cxx +++ b/simgear/scene/model/ModelRegistry.cxx @@ -397,7 +397,7 @@ ModelRegistry::readImage(const string& fileName, if (iter != imageCallbackMap.end() && iter->second.valid()) return iter->second->readImage(fileName, opt); string absFileName = SGModelLib::findDataFile(fileName, opt); - + string originalFileName = absFileName; if (!fileExists(absFileName)) { SG_LOG(SG_IO, SG_ALERT, "Cannot find image file \"" << fileName << "\""); @@ -429,18 +429,26 @@ ModelRegistry::readImage(const string& fileName, // SG_LOG(SG_IO, SG_ALERT, "Hash for " + absFileName + " in cache " + hash); } else { -// SG_LOG(SG_IO, SG_ALERT, "Creating hash for " + absFileName); - hash = f.computeHash(); - filename_hash_cache.insert(absFileName, hash); - boost::optional cacheFilename = filename_hash_cache.findValue(hash); - - // possibly a shared texture - but warn the user to allow investigation. - if (cacheFilename && *cacheFilename != absFileName) { - SG_LOG(SG_IO, SG_ALERT, " Already have " + hash + " : " + *cacheFilename + " not "+absFileName); + // SG_LOG(SG_IO, SG_ALERT, "Creating hash for " + absFileName); + try { + hash = f.computeHash(); } -// SG_LOG(SG_IO, SG_ALERT, " >>>> " + hash + " :: " + newName); + catch (sg_io_exception &e) { + SG_LOG(SG_INPUT, SG_ALERT, "Modelregistry::failed to compute filehash '" << absFileName << "' " << e.getFormattedMessage()); + hash = std::string(); + } + if (hash != std::string()) { + filename_hash_cache.insert(absFileName, hash); + boost::optional cacheFilename = filename_hash_cache.findValue(hash); + + // possibly a shared texture - but warn the user to allow investigation. + if (cacheFilename && *cacheFilename != absFileName) { + SG_LOG(SG_IO, SG_ALERT, " Already have " + hash + " : " + *cacheFilename + " not " + absFileName); + } + // SG_LOG(SG_IO, SG_ALERT, " >>>> " + hash + " :: " + newName); + } + newName = cache_root + "/" + hash.substr(0, 2) + "/" + hash + ".cache.dds"; } - newName = cache_root + "/" + hash.substr(0,2) + "/" + hash + ".cache.dds"; } else { @@ -454,7 +462,7 @@ ModelRegistry::readImage(const string& fileName, // //} - if (fileExists(newName) && doRefresh) { + if (newName != std::string() && fileExists(newName) && doRefresh) { if (!filesCleaned.contains(newName)) { SG_LOG(SG_IO, SG_ALERT, "Removing previously cached effects image " + newName); SGPath(newName).remove(); @@ -463,7 +471,7 @@ ModelRegistry::readImage(const string& fileName, } - if (!fileExists(newName)) { + if (newName != std::string() && !fileExists(newName)) { res = registry->readImageImplementation(absFileName, opt); if (res.validImage()) { osg::ref_ptr srcImage = res.getImage(); @@ -637,7 +645,8 @@ SG_LOG(SG_IO, SG_WARN, pot_message << " " << absFileName); } } else { - absFileName = newName; + if (newName != std::string()) + absFileName = newName; } } } @@ -658,10 +667,8 @@ SG_LOG(SG_IO, SG_WARN, pot_message << " " << absFileName); if (srcImage1->getFileName().empty()) { srcImage1->setFileName(absFileName); } +// srcImage1->setFileName(originalFileName); - if (srcImage1->getName().empty()) { - srcImage1->setName(absFileName); - } if(cache_active && getFileExtension(absFileName) != "dds") { if (processor) {