From 4b735a365b8b03ccac73c4b0aeaaf8c7439b2fd4 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 4 Nov 2021 16:47:43 +0100 Subject: [PATCH] Fix crash when streaming texture with unsupported format by the GPU driver --- Source/Engine/Graphics/Textures/GPUTexture.cpp | 2 ++ Source/Engine/Streaming/Streaming.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/Source/Engine/Graphics/Textures/GPUTexture.cpp b/Source/Engine/Graphics/Textures/GPUTexture.cpp index 4d02f5b5c..e8c6ddbe1 100644 --- a/Source/Engine/Graphics/Textures/GPUTexture.cpp +++ b/Source/Engine/Graphics/Textures/GPUTexture.cpp @@ -497,6 +497,8 @@ bool GPUTexture::Init(const GPUTextureDescription& desc) if (OnInit()) { ReleaseGPU(); + _desc.Clear(); + _residentMipLevels = 0; LOG(Warning, "Cannot initialize texture. Description: {0}", desc.ToString()); return true; } diff --git a/Source/Engine/Streaming/Streaming.cpp b/Source/Engine/Streaming/Streaming.cpp index a5cb65eee..be9337575 100644 --- a/Source/Engine/Streaming/Streaming.cpp +++ b/Source/Engine/Streaming/Streaming.cpp @@ -155,6 +155,13 @@ void UpdateResource(StreamableResource* resource, DateTime now, double currentTi resource->RequestStreamingUpdate(); return; } + else if (resource->GetAllocatedResidency() < targetResidency) + { + // Allocation failed (eg. texture format is not supported or run out of memory) + resource->Streaming.TargetResidency = 0; + resource->Streaming.LastUpdate = DateTime::MaxValue().Ticks; + return; + } } // Calculate residency level to stream in (resources may want to increase/decrease it's quality in steps rather than at once)