diff --git a/Source/Engine/Graphics/Textures/StreamingTexture.cpp b/Source/Engine/Graphics/Textures/StreamingTexture.cpp index 45a11d52c..b28932582 100644 --- a/Source/Engine/Graphics/Textures/StreamingTexture.cpp +++ b/Source/Engine/Graphics/Textures/StreamingTexture.cpp @@ -345,8 +345,12 @@ protected: if (texture == nullptr) return Result::MissingResources; - // Ensure that texture has been allocated before this task - ASSERT(texture->IsAllocated()); + // Ensure that texture has been allocated before this task and has proper format + if (!texture->IsAllocated() || texture->Format() != _streamingTexture->GetHeader()->Format) + { + LOG(Error, "Cannot stream texture {0} (streaming format: {1})", texture->ToString(), (int32)_streamingTexture->GetHeader()->Format); + return Result::Failed; + } // Get asset data BytesContainer data; @@ -385,6 +389,16 @@ protected: // Base GPUUploadTextureMipTask::OnEnd(); } + void OnFail() override + { + if (_streamingTexture) + { + // Stop streaming on fail + _streamingTexture->CancelStreaming(); + } + + GPUUploadTextureMipTask::OnFail(); + } }; Task* StreamingTexture::CreateStreamingTask(int32 residency) diff --git a/Source/Engine/Streaming/StreamableResource.h b/Source/Engine/Streaming/StreamableResource.h index 27551b850..81cffcb93 100644 --- a/Source/Engine/Streaming/StreamableResource.h +++ b/Source/Engine/Streaming/StreamableResource.h @@ -115,10 +115,12 @@ public: /// /// Requests the streaming update for this resource during next streaming manager update. /// - void RequestStreamingUpdate() - { - Streaming.LastUpdate = 0; - } + void RequestStreamingUpdate(); + + /// + /// Stops the streaming (eg. on streaming fail). + /// + void CancelStreaming(); protected: diff --git a/Source/Engine/Streaming/Streaming.cpp b/Source/Engine/Streaming/Streaming.cpp index be9337575..91497a9e1 100644 --- a/Source/Engine/Streaming/Streaming.cpp +++ b/Source/Engine/Streaming/Streaming.cpp @@ -79,6 +79,17 @@ StreamableResource::~StreamableResource() StopStreaming(); } +void StreamableResource::RequestStreamingUpdate() +{ + Streaming.LastUpdate = 0; +} + +void StreamableResource::CancelStreaming() +{ + Streaming.TargetResidency = 0; + Streaming.LastUpdate = DateTime::MaxValue().Ticks; +} + void StreamableResource::StartStreaming(bool isDynamic) { _isDynamic = isDynamic; @@ -158,8 +169,7 @@ void UpdateResource(StreamableResource* resource, DateTime now, double currentTi 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; + resource->CancelStreaming(); return; } }