Fix native library resolver not working after hot-reload

This commit is contained in:
2022-12-24 03:13:40 +02:00
parent 48214f925b
commit 759a9bd365
5 changed files with 53 additions and 13 deletions

View File

@@ -121,6 +121,12 @@ void* CoreCLR::GetStaticMethodPointer(const String& methodName)
return fun;
}
void CoreCLR::RegisterNativeLibrary(const char* moduleName, const char* modulePath)
{
static void* RegisterNativeLibraryPtr = CoreCLR::GetStaticMethodPointer(TEXT("RegisterNativeLibrary"));
CoreCLR::CallStaticMethod<void, const char*, const char*>(RegisterNativeLibraryPtr, moduleName, modulePath);
}
void* CoreCLR::Allocate(int size)
{
#if PLATFORM_WINDOWS

View File

@@ -47,6 +47,8 @@ public:
return ((fun)methodPtr)(args...);
}
static void RegisterNativeLibrary(const char* moduleName, const char* modulePath);
static const char* GetClassFullname(void* klass);
static void* Allocate(int size);
static void Free(void* ptr);

View File

@@ -135,8 +135,9 @@ bool MCore::LoadEngine()
return false;
// Prepare managed side
const String hostExecutable = Platform::GetExecutableFilePath();
CoreCLR::CallStaticMethodByName<void, const Char*>(TEXT("Init"), hostExecutable.Get());
const StringAnsi hostExecutable(Platform::GetExecutableFilePath());
CoreCLR::CallStaticMethodByName<void>(TEXT("Init"));
CoreCLR::RegisterNativeLibrary("FlaxEngine", hostExecutable.Get());
MRootDomain = New<MDomain>("Root");
MDomains.Add(MRootDomain);

View File

@@ -34,6 +34,9 @@
#include <ThirdParty/mono-2.0/mono/metadata/mono-debug.h>
#include <ThirdParty/mono-2.0/mono/metadata/object.h>
#endif
#if USE_NETCORE
#include "DotNet/CoreCLR.h"
#endif
extern void registerFlaxEngineInternalCalls();
@@ -408,6 +411,13 @@ bool Scripting::LoadBinaryModules(const String& path, const String& projectFolde
LOG(Error, "Failed to load C# assembly '{0}' for binary module {1}.", managedPath, name);
return true;
}
#if USE_NETCORE
// Provide new path of hot-reloaded native library path for managed DllImport
if (nativePath.HasChars())
{
CoreCLR::RegisterNativeLibrary(nameAnsi.Get(), StringAnsi(nativePath).Get());
}
#endif
}
#endif