MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / LoadAssetChunk

Method LoadAssetChunk

Source/Engine/Content/Storage/FlaxStorage.cpp:711–804  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

709}
710
711bool FlaxStorage::LoadAssetChunk(FlaxChunk* chunk)
712{
713 PROFILE_MEM(ContentFiles);
714 ASSERT(IsLoaded());
715 ASSERT(chunk != nullptr && _chunks.Contains(chunk));
716
717#if PLATFORM_THREADS_LIMIT > 1
718 // Protect against loading the same chunk from multiple threads at once
719 while (Platform::InterlockedCompareExchange(&chunk->IsLoading, 1, 0) != 0)
720 Platform::Sleep(1);
721 SCOPE_EXIT{ Platform::AtomicStore(&chunk->IsLoading, 0); };
722#endif
723 if (chunk->IsLoaded())
724 return false;
725
726 // Ensure that asset is in a file
727 if (chunk->ExistsInFile() == false)
728 {
729 LOG(Warning, "Cannot load chunk from {0}. It doesn't exist in storage.", ToString());
730 return true;
731 }
732
733 LockChunks();
734
735 // Open file
736 auto stream = OpenFile();
737 bool failed = stream == nullptr;
738 if (!failed)
739 {
740 // Seek
741 stream->SetPosition(chunk->LocationInFile.Address);
742
743 if (stream->HasError())
744 {
745 // Sometimes stream->HasError() from setposition. result in a crash or missing media in release (stream _file._handle = nullptr).
746 // When retrying, it looks like it works and we can continue. We need this to success.
747
748 for (int retry = 0; retry < 5; retry++)
749 {
750 Platform::Sleep(50);
751 stream = OpenFile();
752 failed = stream == nullptr;
753 if (!failed)
754 {
755 stream->SetPosition(chunk->LocationInFile.Address);
756 if (!stream->HasError())
757 break;
758 }
759 }
760 }
761
762 if (!stream || stream->HasError())
763 {
764 failed = true;
765 UnlockChunks();
766 LOG(Warning, "SetPosition failed on chunk {0}.", ToString());
767 return failed;
768 }

Callers 9

TryGetImportOptionsMethod · 0.80
loadAssetMethod · 0.80
LoadChunkMethod · 0.80
LoadChunksMethod · 0.80
loadAssetMethod · 0.80
UpgradeAssetMethod · 0.80
runMethod · 0.80
ProcessTextureBaseFunction · 0.80
PackageMethod · 0.80

Calls 15

OpenFileFunction · 0.85
UnlockChunksFunction · 0.85
EnumHasAnyFlagsFunction · 0.85
LZ4_decompress_safeFunction · 0.85
RegisterUsageMethod · 0.80
IsLoadedFunction · 0.70
AtomicStoreFunction · 0.50
ToStringFunction · 0.50
ContainsMethod · 0.45
IsLoadedMethod · 0.45
SetPositionMethod · 0.45

Tested by

no test coverage detected