summaryrefslogtreecommitdiffstats
path: root/AssetLoader/src/GLTFLoader.cpp
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-11-25 05:41:27 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-11-25 05:41:27 +0000
commit213b9b3c3076afd1d5a8ec7a04d1e5277a8a2623 (patch)
tree896048590263fa0e832727a85ec22cab7fdbf5f5 /AssetLoader/src/GLTFLoader.cpp
parentFixed Mac/iOS clang warnings (diff)
downloadDiligentTools-213b9b3c3076afd1d5a8ec7a04d1e5277a8a2623.tar.gz
DiligentTools-213b9b3c3076afd1d5a8ec7a04d1e5277a8a2623.zip
GLTF loader: fixed crash when texture is missing
Diffstat (limited to 'AssetLoader/src/GLTFLoader.cpp')
-rw-r--r--AssetLoader/src/GLTFLoader.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/AssetLoader/src/GLTFLoader.cpp b/AssetLoader/src/GLTFLoader.cpp
index fc8422e..882589f 100644
--- a/AssetLoader/src/GLTFLoader.cpp
+++ b/AssetLoader/src/GLTFLoader.cpp
@@ -38,6 +38,7 @@
#include "FileWrapper.hpp"
#include "GraphicsAccessories.hpp"
#include "TextureLoader.h"
+#include "GraphicsUtilities.h"
#define TINYGLTF_IMPLEMENTATION
#define TINYGLTF_NO_STB_IMAGE
@@ -722,7 +723,25 @@ void Model::LoadTextures(IRenderDevice* pDevice,
}
}
- VERIFY_EXPR(pTexture);
+ if (!pTexture)
+ {
+ // Create stub texture
+ TextureDesc TexDesc;
+ TexDesc.Name = "Checkerboard stub texture";
+ TexDesc.Type = RESOURCE_DIM_TEX_2D;
+ TexDesc.Width = 32;
+ TexDesc.Height = 32;
+ TexDesc.Format = TEX_FORMAT_RGBA8_UNORM;
+ TexDesc.MipLevels = 1;
+ TexDesc.Usage = USAGE_IMMUTABLE;
+ TexDesc.BindFlags = BIND_SHADER_RESOURCE;
+
+ std::vector<Uint8> Data(TexDesc.Width * TexDesc.Height * 4);
+ TextureSubResData Mip0Data{Data.data(), TexDesc.Width * 4};
+ GenerateCheckerBoardPattern(TexDesc.Width, TexDesc.Height, TexDesc.Format, 4, 4, Data.data(), Mip0Data.Stride);
+ TextureData InitData{&Mip0Data, 1};
+ pDevice->CreateTexture(TexDesc, &InitData, &pTexture);
+ }
if (pTexture && pTextureCache != nullptr)
{