Merge remote-tracking branch 'origin/master' into 1.8
# Conflicts: # Source/Editor/Utilities/EditorUtilities.cpp # Source/Editor/Utilities/EditorUtilities.h
This commit is contained in:
@@ -58,8 +58,8 @@ FlaxStorageReference ContentStorageManager::GetStorage(const StringView& path, b
|
||||
Locker.Lock();
|
||||
|
||||
// Try fast lookup
|
||||
FlaxStorage* result;
|
||||
if (!StorageMap.TryGet(path, result))
|
||||
FlaxStorage* storage;
|
||||
if (!StorageMap.TryGet(path, storage))
|
||||
{
|
||||
// Detect storage type and create object
|
||||
const bool isPackage = path.EndsWith(StringView(PACKAGE_FILES_EXTENSION));
|
||||
@@ -67,39 +67,42 @@ FlaxStorageReference ContentStorageManager::GetStorage(const StringView& path, b
|
||||
{
|
||||
auto package = New<FlaxPackage>(path);
|
||||
Packages.Add(package);
|
||||
result = package;
|
||||
storage = package;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto file = New<FlaxFile>(path);
|
||||
Files.Add(file);
|
||||
result = file;
|
||||
storage = file;
|
||||
}
|
||||
|
||||
// Register storage container
|
||||
StorageMap.Add(path, result);
|
||||
StorageMap.Add(path, storage);
|
||||
}
|
||||
|
||||
// Build reference (before releasing the lock so ContentStorageSystem::Job won't delete it when running from async thread)
|
||||
FlaxStorageReference result(storage);
|
||||
|
||||
Locker.Unlock();
|
||||
|
||||
if (loadIt)
|
||||
{
|
||||
// Initialize storage container
|
||||
result->LockChunks();
|
||||
const bool loadFailed = result->Load();
|
||||
result->UnlockChunks();
|
||||
storage->LockChunks();
|
||||
const bool loadFailed = storage->Load();
|
||||
storage->UnlockChunks();
|
||||
if (loadFailed)
|
||||
{
|
||||
LOG(Error, "Failed to load {0}.", path);
|
||||
Locker.Lock();
|
||||
StorageMap.Remove(path);
|
||||
if (result->IsPackage())
|
||||
Packages.Remove((FlaxPackage*)result);
|
||||
if (storage->IsPackage())
|
||||
Packages.Remove((FlaxPackage*)storage);
|
||||
else
|
||||
Files.Remove((FlaxFile*)result);
|
||||
Files.Remove((FlaxFile*)storage);
|
||||
Locker.Unlock();
|
||||
Delete(result);
|
||||
return nullptr;
|
||||
result = nullptr;
|
||||
Delete(storage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -211,7 +211,13 @@ FlaxStorage::~FlaxStorage()
|
||||
|
||||
#if USE_EDITOR
|
||||
// Ensure to close any outstanding file handles to prevent file locking in case it failed to load
|
||||
_file.DeleteAll();
|
||||
Array<FileReadStream*> streams;
|
||||
_file.GetValues(streams);
|
||||
for (FileReadStream* stream : streams)
|
||||
{
|
||||
if (stream)
|
||||
Delete(stream);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1266,7 +1272,6 @@ bool FlaxStorage::LoadAssetHeader(const Entry& e, AssetInitData& data)
|
||||
}
|
||||
|
||||
#if ASSETS_LOADING_EXTRA_VERIFICATION
|
||||
|
||||
// Validate loaded header (asset ID and type ID must be the same)
|
||||
if (e.ID != data.Header.ID)
|
||||
{
|
||||
@@ -1276,7 +1281,6 @@ bool FlaxStorage::LoadAssetHeader(const Entry& e, AssetInitData& data)
|
||||
{
|
||||
LOG(Error, "Loading asset header data mismatch! Expected Type Name: {0}, loaded header: {1}.\nSource: {2}", e.TypeName, data.Header.ToString(), ToString());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return false;
|
||||
@@ -1339,7 +1343,14 @@ bool FlaxStorage::CloseFileHandles()
|
||||
return true; // Failed, someone is still accessing the file
|
||||
|
||||
// Close file handles (from all threads)
|
||||
_file.DeleteAll();
|
||||
Array<FileReadStream*> streams;
|
||||
_file.GetValues(streams);
|
||||
for (FileReadStream* stream : streams)
|
||||
{
|
||||
if (stream)
|
||||
Delete(stream);
|
||||
}
|
||||
_file.Clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ protected:
|
||||
CriticalSection _loadLocker;
|
||||
|
||||
// Storage
|
||||
ThreadLocalObject<FileReadStream> _file;
|
||||
ThreadLocal<FileReadStream*> _file;
|
||||
Array<FlaxChunk*> _chunks;
|
||||
|
||||
// Metadata
|
||||
|
||||
@@ -58,17 +58,17 @@ public:
|
||||
return _storage != nullptr;
|
||||
}
|
||||
|
||||
FORCE_INLINE bool operator ==(const FlaxStorageReference& other) const
|
||||
FORCE_INLINE bool operator==(const FlaxStorageReference& other) const
|
||||
{
|
||||
return _storage == other._storage;
|
||||
}
|
||||
|
||||
FORCE_INLINE bool operator !=(const FlaxStorageReference& other) const
|
||||
FORCE_INLINE bool operator!=(const FlaxStorageReference& other) const
|
||||
{
|
||||
return _storage != other._storage;
|
||||
}
|
||||
|
||||
FORCE_INLINE FlaxStorage* operator ->() const
|
||||
FORCE_INLINE FlaxStorage* operator->() const
|
||||
{
|
||||
return _storage;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user