Fix crash when closing handles to asset file while any asset streaming task is active for asset from that file

This commit is contained in:
Wojciech Figat
2022-07-18 13:02:34 +02:00
parent b6652a61c6
commit 3dbff3cab7
14 changed files with 119 additions and 11 deletions

View File

@@ -9,6 +9,8 @@
#include "Engine/Platform/File.h"
#include "Engine/Profiler/ProfilerCPU.h"
#include "Engine/Serialization/FileWriteStream.h"
#include "Engine/Content/Asset.h"
#include "Engine/Content/Content.h"
#include "Engine/Threading/Threading.h"
#if USE_EDITOR
#include "Engine/Serialization/JsonWriter.h"
@@ -1289,9 +1291,24 @@ void FlaxStorage::CloseFileHandles()
// In those situations all the async tasks using this storage should be cancelled externally
// Ensure that no one is using this resource
int32 waitTime = 500;
int32 waitTime = 10;
while (Platform::AtomicRead(&_chunksLock) != 0 && waitTime-- > 0)
Platform::Sleep(10);
if (Platform::AtomicRead(&_chunksLock) != 0)
{
// File can be locked by some streaming tasks (eg. AudioClip::StreamingTask or StreamModelLODTask)
for (int32 i = 0; i < GetEntriesCount(); i++)
{
Entry e;
GetEntry(i, e);
Asset* asset = Content::GetAsset(e.ID);
if (asset)
{
LOG(Info, "Canceling streaming for asset {0}", asset->ToString());
asset->CancelStreaming();
}
}
}
ASSERT(_chunksLock == 0);
_file.DeleteAll();