diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-03-25 01:26:41 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-03-25 01:26:41 +0000 |
| commit | 785293d9844b07f47a4269b580412ae3af7ce891 (patch) | |
| tree | c3c2358f605599c0c8c87486d0648ae5e246a3ed /AssetLoader/src/GLTFLoader.cpp | |
| parent | Updated ImGuiUtils: added ScopedID helper class (diff) | |
| download | DiligentTools-785293d9844b07f47a4269b580412ae3af7ce891.tar.gz DiligentTools-785293d9844b07f47a4269b580412ae3af7ce891.zip | |
GLTF loader: fixed few issues with handling texture loading errors
Diffstat (limited to 'AssetLoader/src/GLTFLoader.cpp')
| -rw-r--r-- | AssetLoader/src/GLTFLoader.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
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<ITexture> 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<Uint8> 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); + } + } } } |
