From 785293d9844b07f47a4269b580412ae3af7ce891 Mon Sep 17 00:00:00 2001 From: assiduous Date: Tue, 24 Mar 2020 18:26:41 -0700 Subject: GLTF loader: fixed few issues with handling texture loading errors --- AssetLoader/src/GLTFLoader.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'AssetLoader/src/GLTFLoader.cpp') diff --git a/AssetLoader/src/GLTFLoader.cpp b/AssetLoader/src/GLTFLoader.cpp index f97b04f..cf454bd 100644 --- a/AssetLoader/src/GLTFLoader.cpp +++ b/AssetLoader/src/GLTFLoader.cpp @@ -56,6 +56,15 @@ RefCntAutoPtr TextureFromGLTFImage(IRenderDevice* pDevice, const tinygltf::Image& gltfimage, ISampler* pSampler) { + if (gltfimage.image.empty()) + { + LOG_ERROR_AND_THROW("Failed to create texture for image ", gltfimage.uri, ": no data available."); + } + if (gltfimage.width <= 0 || gltfimage.height <= 0 || gltfimage.component <= 0) + { + LOG_ERROR_AND_THROW("Failed to create texture for image ", gltfimage.uri, ": invalid parameters."); + } + std::vector RGBA; const Uint8* pTextureData = nullptr; @@ -481,8 +490,20 @@ void Model::LoadTextures(IRenderDevice* pDevice, if (it != pTextureCache->end()) { pTexture = it->second.Lock(); - VERIFY(pTexture, "Stale textures should not be found in the texture cache because we intentionally keep strong references. " - "This must be an unexpected effect of loading resources from multiple threads."); + if (!pTexture) + { + // Image width and height are initialized by LoadImageData() if the texture is found + // in the cache. + if (gltf_image.width > 0 && gltf_image.height > 0) + { + UNEXPECTED("Stale textures should not be found in the texture cache because we hold strong references. " + "This must be an unexpected effect of loading resources from multiple threads or a bug."); + } + else + { + pTextureCache->erase(it); + } + } } } -- cgit v1.2.3