From f8670a497e5a0b5524e0bfe159e4c31a8dc5961d Mon Sep 17 00:00:00 2001 From: Wojciech Figat Date: Fri, 25 Mar 2022 10:10:23 +0100 Subject: [PATCH] Fix crash when loading model SDF on older GPUs (d3d10) --- Source/Engine/Content/Assets/Model.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Content/Assets/Model.cpp b/Source/Engine/Content/Assets/Model.cpp index 79a7d869c..507360611 100644 --- a/Source/Engine/Content/Assets/Model.cpp +++ b/Source/Engine/Content/Assets/Model.cpp @@ -13,6 +13,7 @@ #include "Engine/Graphics/Models/ModelInstanceEntry.h" #include "Engine/Streaming/StreamingGroup.h" #include "Engine/Debug/Exceptions/ArgumentOutOfRangeException.h" +#include "Engine/Graphics/GPUDevice.h" #include "Engine/Graphics/Async/GPUTask.h" #include "Engine/Graphics/Textures/GPUTexture.h" #include "Engine/Graphics/Textures/TextureData.h" @@ -121,9 +122,16 @@ protected: REGISTER_BINARY_ASSET_WITH_UPGRADER(Model, "FlaxEngine.Model", ModelAssetUpgrader, true); +static byte EnableModelSDF = 0; + Model::Model(const SpawnParams& params, const AssetInfo* info) : ModelBase(params, info, StreamingGroups::Instance()->Models()) { + if (EnableModelSDF == 0 && GPUDevice::Instance) + { + const bool enable = GPUDevice::Instance->GetFeatureLevel() >= FeatureLevel::SM5; + EnableModelSDF = enable ? 1 : 2; + } } Model::~Model() @@ -598,6 +606,8 @@ bool Model::Save(bool withMeshDataFromGpu, const StringView& path) bool Model::GenerateSDF(float resolutionScale, int32 lodIndex, bool cacheData) { + if (EnableModelSDF == 2) + return true; // Not supported ScopeLock lock(Locker); if (!HasAnyLODInitialized()) return true; @@ -885,7 +895,7 @@ Asset::LoadResult Model::load() // Load SDF auto chunk15 = GetChunk(15); - if (chunk15 && chunk15->IsLoaded()) + if (chunk15 && chunk15->IsLoaded() && EnableModelSDF == 1) { MemoryReadStream sdfStream(chunk15->Get(), chunk15->Size()); int32 version;