Don't crash when failing to convert a texture to KTX format

This commit is contained in:
Brad Davis 2017-03-14 09:09:14 -07:00
parent 3bef5ad528
commit 1ccf715e3b

View file

@ -526,16 +526,20 @@ void ImageReader::read() {
// Save the image into a KTXFile // Save the image into a KTXFile
auto ktx = gpu::Texture::serialize(*texture); auto ktx = gpu::Texture::serialize(*texture);
const char* data = reinterpret_cast<const char*>(ktx->_storage->data()); if (ktx) {
size_t length = ktx->_storage->size(); const char* data = reinterpret_cast<const char*>(ktx->_storage->data());
KTXFilePointer file; size_t length = ktx->_storage->size();
auto& ktxCache = DependencyManager::get<TextureCache>()->_ktxCache; KTXFilePointer file;
if (!ktx || !(file = ktxCache.writeFile(data, KTXCache::Metadata(_hash, length)))) { auto& ktxCache = DependencyManager::get<TextureCache>()->_ktxCache;
qCWarning(modelnetworking) << _url << "file cache failed"; if (!ktx || !(file = ktxCache.writeFile(data, KTXCache::Metadata(_hash, length)))) {
qCWarning(modelnetworking) << _url << "file cache failed";
} else {
resource.staticCast<NetworkTexture>()->_file = file;
auto ktx = file->getKTX();
texture->setKtxBacking(ktx);
}
} else { } else {
resource.staticCast<NetworkTexture>()->_file = file; qCWarning(modelnetworking) << "Unable to serialize texture to KTX " << _url;
auto ktx = file->getKTX();
texture->setKtxBacking(ktx);
} }
} }