From 1d9f5e8cfe5bc480561a4f4f33bf0fcaef6dd9b3 Mon Sep 17 00:00:00 2001 From: Preben Eriksen Date: Mon, 31 Oct 2022 16:07:43 +0100 Subject: [PATCH] PE: Fixed - flax storage crash , happened quit often on my system. --- Source/Engine/Content/Storage/FlaxStorage.cpp | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Source/Engine/Content/Storage/FlaxStorage.cpp b/Source/Engine/Content/Storage/FlaxStorage.cpp index 47610be77..a9798fb0c 100644 --- a/Source/Engine/Content/Storage/FlaxStorage.cpp +++ b/Source/Engine/Content/Storage/FlaxStorage.cpp @@ -622,6 +622,33 @@ bool FlaxStorage::LoadAssetChunk(FlaxChunk* chunk) // Seek stream->SetPosition(chunk->LocationInFile.Address); + if (stream->HasError()) + { + // Sometimes stream->HasError() from setposition. result in a crash or missing media in release (stream _file._handle = nullptr). + // When retrying, it looks like it works and we can continue. We need this to success. + + for (int retry = 0; retry < 5; retry++) + { + Platform::Sleep(50); + stream = OpenFile(); + failed = stream == nullptr; + if (!failed) + { + stream->SetPosition(chunk->LocationInFile.Address); + } + if (!stream->HasError()) + break; + } + } + + if (stream->HasError()) + { + failed = true; + UnlockChunks(); + LOG(Warning, "SetPosition failed on chunk {0}.", ToString()); + return failed; + } + // Load data auto size = chunk->LocationInFile.Size; if (chunk->Flags & FlaxChunkFlags::CompressedLZ4)