Minor changes to hot reload code
This commit is contained in:
@@ -6,10 +6,6 @@
|
|||||||
#include <Core/HotReload/HotReload.h>
|
#include <Core/HotReload/HotReload.h>
|
||||||
#include <Core/Memory/Allocator.h>
|
#include <Core/Memory/Allocator.h>
|
||||||
|
|
||||||
#define MAX_ATTEMPT 256
|
|
||||||
#define MAX_DLL_ID 32767
|
|
||||||
#define TEMP_DLL_BUFFER_SIZE_FOR_ID 6 // MAX_DLL_ID + _
|
|
||||||
|
|
||||||
namespace Juliet
|
namespace Juliet
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
@@ -27,6 +23,9 @@ namespace Juliet
|
|||||||
return lastWriteTime;
|
return lastWriteTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr size_t kMaxAttempts = 256;
|
||||||
|
constexpr size_t kMaxDLLID = 256;
|
||||||
|
constexpr size_t kTempDLLBufferSizeForID = 6; // ID numbers + \0
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void LoadCode(HotReloadCode& code)
|
void LoadCode(HotReloadCode& code)
|
||||||
@@ -52,37 +51,34 @@ namespace Juliet
|
|||||||
const char* basePath = GetBasePath();
|
const char* basePath = GetBasePath();
|
||||||
size_t basePathLength = strlen(basePath);
|
size_t basePathLength = strlen(basePath);
|
||||||
|
|
||||||
StringBuffer<char> tempDllPath = {};
|
const size_t tempDllMaxBufferSize = basePathLength + code.TransientDLLName.Size + kTempDLLBufferSizeForID;
|
||||||
const size_t tempDllMaxBufferSize = basePathLength + code.TransientDLLName.Size + TEMP_DLL_BUFFER_SIZE_FOR_ID;
|
auto tempDllPath = static_cast<char*>(Calloc(tempDllMaxBufferSize, sizeof(char)));
|
||||||
tempDllPath.Data = static_cast<char*>(Calloc(tempDllMaxBufferSize, sizeof(char)));
|
for (uint32 attempt = 0; attempt < kMaxAttempts; ++attempt)
|
||||||
|
|
||||||
char idToStr[TEMP_DLL_BUFFER_SIZE_FOR_ID];
|
|
||||||
for (uint32 attempt = 0; attempt < MAX_ATTEMPT; ++attempt)
|
|
||||||
{
|
{
|
||||||
// int to char
|
// int to char
|
||||||
int idLength = snprintf(idToStr, sizeof(idToStr), "%u", code.UniqueID);
|
char idToStr[kTempDLLBufferSizeForID];
|
||||||
|
int idLength = snprintf(idToStr, sizeof(idToStr), "%u", code.UniqueID);
|
||||||
|
|
||||||
int writtenSize = snprintf(tempDllPath.Data, tempDllMaxBufferSize, "%s%u_%s", basePath, code.UniqueID,
|
int writtenSize = snprintf(tempDllPath, tempDllMaxBufferSize, "%s%u_%s", basePath, code.UniqueID,
|
||||||
code.TransientDLLName.Data);
|
code.TransientDLLName.Data);
|
||||||
if (writtenSize < static_cast<int>(basePathLength + idLength + code.TransientDLLName.Size))
|
if (writtenSize < static_cast<int>(basePathLength + idLength + code.TransientDLLName.Size))
|
||||||
{
|
{
|
||||||
SafeFree(tempDllPath.Data);
|
SafeFree(tempDllPath);
|
||||||
Log(LogLevel::Error, LogCategory::Core, "Cannot create temp full path");
|
Log(LogLevel::Error, LogCategory::Core, "Cannot create temp full path");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tempDllPath.Size = writtenSize + 1;
|
|
||||||
|
|
||||||
if (++code.UniqueID >= MAX_DLL_ID)
|
if (++code.UniqueID >= kMaxDLLID)
|
||||||
{
|
{
|
||||||
code.UniqueID = 0;
|
code.UniqueID = 0;
|
||||||
}
|
}
|
||||||
if (CopyFileA(dllName, tempDllPath.Data, false))
|
if (CopyFileA(dllName, tempDllPath, false))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
code.Dll = LoadDynamicLibrary(tempDllPath.Data);
|
code.Dll = LoadDynamicLibrary(tempDllPath);
|
||||||
if (code.Dll)
|
if (code.Dll)
|
||||||
{
|
{
|
||||||
code.IsValid = true;
|
code.IsValid = true;
|
||||||
@@ -99,8 +95,7 @@ namespace Juliet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SafeFree(tempDllPath.Data);
|
SafeFree(tempDllPath);
|
||||||
tempDllPath = {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!code.IsValid)
|
if (!code.IsValid)
|
||||||
|
|||||||
Reference in New Issue
Block a user