Initialize ScriptingService earlier

This commit is contained in:
2023-08-11 17:09:38 +03:00
parent 9e8865bd12
commit 983c22a3a6
8 changed files with 24 additions and 28 deletions

View File

@@ -45,10 +45,8 @@ public:
/// </summary>
static void UnloadEngine();
#if USE_EDITOR
// Called by Scripting in a middle of hot-reload (after unloading modules but before loading them again).
static void ReloadScriptingAssemblyLoadContext();
#endif
// Called by Scripting during initialization or in a middle of hot-reload (after unloading modules but before loading them again).
static void LoadScriptingAssemblyLoadContext();
public:
/// <summary>

View File

@@ -269,6 +269,8 @@ bool MCore::LoadEngine()
// Prepare managed side
CallStaticMethod<void>(GetStaticMethodPointer(TEXT("Init")));
MCore::LoadScriptingAssemblyLoadContext();
#ifdef MCORE_MAIN_MODULE_NAME
// MCORE_MAIN_MODULE_NAME define is injected by Scripting.Build.cs on platforms that use separate shared library for engine symbols
::String flaxLibraryPath(Platform::GetMainDirectory() / TEXT(MACRO_TO_STR(MCORE_MAIN_MODULE_NAME)));
@@ -311,20 +313,16 @@ void MCore::UnloadEngine()
ShutdownHostfxr();
}
#if USE_EDITOR
void MCore::ReloadScriptingAssemblyLoadContext()
void MCore::LoadScriptingAssemblyLoadContext()
{
// Clear any cached class attributes (see https://github.com/FlaxEngine/FlaxEngine/issues/1108)
for (auto e : CachedClassHandles)
e.Value->_attributes.Clear();
static void* ReloadScriptingAssemblyLoadContextPtr = GetStaticMethodPointer(TEXT("ReloadScriptingAssemblyLoadContext"));
CallStaticMethod<void>(ReloadScriptingAssemblyLoadContextPtr);
static void* LoadScriptingAssemblyLoadContextPtr = GetStaticMethodPointer(TEXT("LoadScriptingAssemblyLoadContext"));
CallStaticMethod<void>(LoadScriptingAssemblyLoadContextPtr);
}
#endif
MObject* MCore::Object::Box(void* value, const MClass* klass)
{
static void* BoxValuePtr = GetStaticMethodPointer(TEXT("BoxValue"));

View File

@@ -717,7 +717,7 @@ void MCore::UnloadEngine()
#if USE_EDITOR
void MCore::ReloadScriptingAssemblyLoadContext()
void MCore::LoadScriptingAssemblyLoadContext()
{
}

View File

@@ -60,7 +60,7 @@ void MCore::UnloadEngine()
#if USE_EDITOR
void MCore::ReloadScriptingAssemblyLoadContext()
void MCore::LoadScriptingAssemblyLoadContext()
{
}

View File

@@ -39,7 +39,7 @@ class ScriptingService : public EngineService
{
public:
ScriptingService()
: EngineService(TEXT("Scripting"), -20)
: EngineService(TEXT("Scripting"), -999)
{
}
@@ -703,7 +703,7 @@ void Scripting::Reload(bool canTriggerSceneReload)
_hasGameModulesLoaded = false;
// Release and create a new assembly load context for user assemblies
MCore::ReloadScriptingAssemblyLoadContext();
MCore::LoadScriptingAssemblyLoadContext();
// Give GC a try to cleanup old user objects and the other mess
MCore::GC::Collect();
@@ -1091,9 +1091,6 @@ bool initFlaxEngine()
}
#endif
// TODO: move it somewhere to game instance class or similar
MainRenderTask::Instance = New<MainRenderTask>();
return false;
}