Skip to content

Commit f250802

Browse files
Fixes for clean shutdown.
1 parent 0deb7f1 commit f250802

9 files changed

Lines changed: 44 additions & 6 deletions

File tree

Engine/Source/AssetSystemModule/Private/AssetSystem/AssetCache.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ namespace Volt
2626

2727
AssetCache::~AssetCache()
2828
{
29+
ValidateAllocatorEmpty();
30+
2931
VT_ENSURE_MSG(m_hashTable.IsEmpty(), "Cache should have been cleared before destruction!");
3032
}
3133

@@ -167,4 +169,12 @@ namespace Volt
167169
{
168170
m_hashTable.Reserve(AssetRegistry::GetNumMaxAssets());
169171
}
172+
173+
void AssetCache::ValidateAllocatorEmpty()
174+
{
175+
for (auto it = ContainerAllocator::Iterator(m_allocator); it; ++it)
176+
{
177+
VT_LOG(Error, "Asset {} has not been destroy properly!", it->asset->GetAssetName());
178+
}
179+
}
170180
}

Engine/Source/AssetSystemModule/Private/AssetSystem/AssetManager.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace Volt
3737

3838
AssetManager::~AssetManager()
3939
{
40-
RunGarbageCollection(0, true);
40+
CollectGarbageOnShutdown();
4141
m_assetCache.Clear();
4242
}
4343

@@ -819,6 +819,16 @@ namespace Volt
819819
}
820820
}
821821

822+
void AssetManager::CollectGarbageOnShutdown()
823+
{
824+
// Since assets may hold references to other assets,
825+
// we must loop until no more assets have been queued.
826+
while (!m_assetEvictionQueue.Empty())
827+
{
828+
RunGarbageCollection(0, true);
829+
}
830+
}
831+
822832
bool AssetManager::SerializeAsset(AssetReference<Asset> asset)
823833
{
824834
ReadOnlyAssetMetadata assetMetadata = GetReadOnlyAssetMetadata(asset->GetAssetHandle());

Engine/Source/AssetSystemModule/Public/AssetSystem/AssetCache.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ namespace Volt
4545

4646
private:
4747
void Initialize();
48+
void ValidateAllocatorEmpty();
49+
50+
using ContainerAllocator = PagedAtomicArenaAllocator<Container, 1024>;
4851

4952
AtomicHashTable<Container*> m_hashTable;
50-
PagedAtomicArenaAllocator<Container, 1024> m_allocator;
53+
ContainerAllocator m_allocator;
5154
};
5255
}

Engine/Source/AssetSystemModule/Public/AssetSystem/AssetManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ namespace Volt
164164

165165
void QueueAssetForEviction(AssetRefCounter* assetRefCounter);
166166
void RunGarbageCollection(uint64_t frameIndex, bool forceCleanupAll);
167+
void CollectGarbageOnShutdown();
167168

168169
bool DeserializeAsset(AssetReference<Asset> asset);
169170

Engine/Source/CoreUtilities/Private/CoreUtilities/MemoryTracker.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,15 @@ void MemoryTracker::OnFree(MemoryTrackerHeader* header)
8484
return;
8585
}
8686

87+
MemoryTracker& instance = Get();
88+
89+
if (header->memoryTagIndex >= instance.m_memoryTagCounters.size())
90+
{
91+
return;
92+
}
93+
8794
g_depth++;
8895

89-
MemoryTracker& instance = Get();
9096
instance.m_memoryTagCounters[header->memoryTagIndex].counter.fetch_sub(header->size, std::memory_order::relaxed);
9197

9298
g_depth--;

Engine/Source/Sandbox/Private/Sandbox/Sandbox.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ void Sandbox::OnDetach()
355355
m_runtimeScene = nullptr;
356356
m_intermediateScene = nullptr;
357357

358+
if (m_sceneContainer)
359+
{
360+
m_sceneManager->UnloadAndFreeScene(m_sceneContainer);
361+
}
362+
358363
s_instance = nullptr;
359364

360365
NodeEditorHelpers::Shutdown();

Engine/Source/Sandbox/Public/Sandbox/Window/AssetBrowser/AssetBrowserConstants.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
namespace AssetBrowser
88
{
9-
typedef PagedAtomicArenaAllocator<AssetBrowser::DirectoryItem, 256> DirectoryItemAllocator;
10-
typedef PagedAtomicArenaAllocator<AssetBrowser::AssetItem, 1024> AssetItemAllocator;
9+
typedef PagedAtomicArenaAllocator<AssetBrowser::DirectoryItem, 256, DefaultHeapAllocator, true> DirectoryItemAllocator;
10+
typedef PagedAtomicArenaAllocator<AssetBrowser::AssetItem, 1024, DefaultHeapAllocator, true> AssetItemAllocator;
1111
}

Engine/Source/Volt-Renderer/Private/Volt-Renderer/RenderScene/RenderScene_Modern.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ namespace Volt
3838

3939
RenderScene_Modern::~RenderScene_Modern()
4040
{
41+
RunGarbageCollection();
42+
4143
DestroyBuffers();
4244
}
4345

Engine/Source/Volt-Scene/Private/Volt-Scene/SceneManager.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <Volt-Renderer/SceneRenderer/ISceneRenderer.h>
77

88
#include <AssetSystem/AssetManager.h>
9+
#include <AssetSystem/AssetManagerSubSystem.h>
910

1011
VT_DECLARE_LOG_CATEGORY(LogSceneManager, LogVerbosity::Trace);
1112
VT_DEFINE_LOG_CATEGORY(LogSceneManager);
@@ -80,7 +81,7 @@ namespace Volt
8081

8182
void SceneManager::GetSubSystemDependencies(SubSystemDependencyList& outDependencies)
8283
{
83-
84+
outDependencies.AddDependency<AssetManagerSubSystem>();
8485
}
8586

8687
SceneContainer::SceneContainer(AssetReference<Scene> scene)

0 commit comments

Comments
 (0)