Revert "Initialize ScriptingService earlier"

This reverts commit 0566e17b23273feffed0c41ed61f7e56d6e8f1a8.
This commit is contained in:
2024-04-18 19:26:38 +03:00
parent a986ede53f
commit c16ec763c2
8 changed files with 28 additions and 24 deletions

View File

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

View File

@@ -278,8 +278,6 @@ 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)));
@@ -322,16 +320,20 @@ void MCore::UnloadEngine()
ShutdownHostfxr();
}
void MCore::LoadScriptingAssemblyLoadContext()
#if USE_EDITOR
void MCore::ReloadScriptingAssemblyLoadContext()
{
// Clear any cached class attributes (see https://github.com/FlaxEngine/FlaxEngine/issues/1108)
for (auto e : CachedClassHandles)
e.Value->_attributes.Clear();
static void* LoadScriptingAssemblyLoadContextPtr = GetStaticMethodPointer(TEXT("LoadScriptingAssemblyLoadContext"));
CallStaticMethod<void>(LoadScriptingAssemblyLoadContextPtr);
static void* ReloadScriptingAssemblyLoadContextPtr = GetStaticMethodPointer(TEXT("ReloadScriptingAssemblyLoadContext"));
CallStaticMethod<void>(ReloadScriptingAssemblyLoadContextPtr);
}
#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::LoadScriptingAssemblyLoadContext()
void MCore::ReloadScriptingAssemblyLoadContext()
{
}

View File

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

View File

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