diff --git a/Juliet/src/Core/HAL/Filesystem/Filesystem.cpp b/Juliet/src/Core/HAL/Filesystem/Filesystem.cpp index fb9e636..e5e8f66 100644 --- a/Juliet/src/Core/HAL/Filesystem/Filesystem.cpp +++ b/Juliet/src/Core/HAL/Filesystem/Filesystem.cpp @@ -26,15 +26,13 @@ namespace Juliet String GetBasePath() { - if (!IsValid(CachedBasePath)) - { - CachedBasePath = Platform::GetBasePath(); - } + Assert(IsValid(CachedBasePath)); return CachedBasePath; } String GetAssetBasePath() { + Assert(IsValid(CachedAssetBasePath)); return CachedAssetBasePath; } @@ -50,7 +48,7 @@ namespace Juliet return {}; } - snprintf(buffer, totalSize, "%s%s", CStr(CachedAssetBasePath), CStr(filename)); + juliet_snprintf(buffer, totalSize, "%s%s", CStr(CachedAssetBasePath), CStr(filename)); return { buffer, totalSize - 1 }; } @@ -63,8 +61,10 @@ namespace Juliet return Platform::IsAbsolutePath(path); } - void InitFilesystem() + void InitFilesystem(NonNullPtr arena) { + CachedBasePath = Platform::GetBasePath(arena); + String basePath = GetBasePath(); Assert(IsValid(basePath)); @@ -76,15 +76,14 @@ namespace Juliet for (const char* candidate : kCandidates) { char probePath[512]; - snprintf(probePath, sizeof(probePath), "%s%s", CStr(basePath), candidate); + juliet_snprintf(probePath, sizeof(probePath), "%s%s", CStr(basePath), candidate); if (DirectoryExists(probePath)) { - size_t len = strlen(probePath); - auto* buffer = static_cast(Calloc(len + 1, sizeof(char))); - if (buffer) + size_t len = strlen(probePath); + if (char* buffer = ArenaPushArray(arena, len + 1 JULIET_DEBUG_PARAM("CachedAssetBasePath"))) { - snprintf(buffer, len + 1, "%s", probePath); + juliet_snprintf(buffer, len + 1, "%s", probePath); CachedAssetBasePath = { buffer, len }; Log(LogLevel::Message, LogCategory::Core, "Asset base path: %s", buffer); } @@ -97,15 +96,9 @@ namespace Juliet void ShutdownFilesystem() { - if (IsValid(CachedBasePath)) - { - CachedBasePath.Size = 0; - SafeFree(CachedBasePath.Str); - } - if (IsValid(CachedAssetBasePath)) - { - CachedAssetBasePath.Size = 0; - SafeFree(CachedAssetBasePath.Str); - } + CachedBasePath.Size = 0; + CachedBasePath.Str = nullptr; + CachedAssetBasePath.Size = 0; + CachedAssetBasePath.Str = nullptr; } } // namespace Juliet diff --git a/Juliet/src/Core/HAL/Filesystem/Filesystem_Platform.h b/Juliet/src/Core/HAL/Filesystem/Filesystem_Platform.h index fdaa89a..edc72ff 100644 --- a/Juliet/src/Core/HAL/Filesystem/Filesystem_Platform.h +++ b/Juliet/src/Core/HAL/Filesystem/Filesystem_Platform.h @@ -2,6 +2,6 @@ namespace Juliet::Platform { - extern String GetBasePath(); + extern String GetBasePath(NonNullPtr arena); extern bool IsAbsolutePath(String path); } // namespace Juliet::Platform diff --git a/Juliet/src/Core/HAL/Filesystem/Filesystem_Private.h b/Juliet/src/Core/HAL/Filesystem/Filesystem_Private.h index c138b01..859cc2a 100644 --- a/Juliet/src/Core/HAL/Filesystem/Filesystem_Private.h +++ b/Juliet/src/Core/HAL/Filesystem/Filesystem_Private.h @@ -2,6 +2,6 @@ namespace Juliet { - extern void InitFilesystem(); + extern void InitFilesystem(NonNullPtr arena); extern void ShutdownFilesystem(); } // namespace Juliet diff --git a/Juliet/src/Core/HAL/Filesystem/Win32/Win32Filesystem.cpp b/Juliet/src/Core/HAL/Filesystem/Win32/Win32Filesystem.cpp index 3d0ab07..a7c1c9c 100644 --- a/Juliet/src/Core/HAL/Filesystem/Win32/Win32Filesystem.cpp +++ b/Juliet/src/Core/HAL/Filesystem/Win32/Win32Filesystem.cpp @@ -7,12 +7,12 @@ namespace Juliet::Platform { - String GetBasePath() + String GetBasePath(NonNullPtr arena) { // Allocate a buffer that could fit the module size. // Max Path is a good start but could be bigger if the path include long path prefix size_t bufferSize = MAX_PATH; - auto buffer = static_cast(Calloc(MAX_PATH, sizeof(char))); + auto buffer = ArenaPushArray(arena, MAX_PATH JULIET_DEBUG_PARAM("BasePath buffer")); if (buffer == nullptr) { return {}; @@ -26,8 +26,9 @@ namespace Juliet::Platform // If the module filename length is bigger than the buffer size, we need to reallocate a bigger buffer if (moduleFilenameLength >= bufferSize - 1) { + char* addedBuffer = ArenaPushArray(arena, bufferSize JULIET_DEBUG_PARAM("BasePath buffer")); + Assert(addedBuffer != nullptr); bufferSize *= 2; - buffer = static_cast(Realloc(buffer, bufferSize * sizeof(char))); } else { @@ -37,7 +38,6 @@ namespace Juliet::Platform if (moduleFilenameLength == 0) { - SafeFree(buffer); Log(LogLevel::Error, LogCategory::Core, "Filesystem: Cannot locate executable path"); } diff --git a/Juliet/src/Engine/Engine.cpp b/Juliet/src/Engine/Engine.cpp index dbe348d..370da57 100644 --- a/Juliet/src/Engine/Engine.cpp +++ b/Juliet/src/Engine/Engine.cpp @@ -160,7 +160,7 @@ namespace Juliet UnitTest::RunUnitTests(); #endif - InitFilesystem(); + InitFilesystem(EngineInstance.PlatformArena); JulietInit(flags); }