Initialize ScriptingService earlier
This commit is contained in:
@@ -1006,7 +1006,7 @@ namespace FlaxEngine.Interop
|
|||||||
}
|
}
|
||||||
|
|
||||||
[UnmanagedCallersOnly]
|
[UnmanagedCallersOnly]
|
||||||
internal static void ReloadScriptingAssemblyLoadContext()
|
internal static void LoadScriptingAssemblyLoadContext()
|
||||||
{
|
{
|
||||||
#if FLAX_EDITOR
|
#if FLAX_EDITOR
|
||||||
// Clear all caches which might hold references to assemblies in collectible ALC
|
// Clear all caches which might hold references to assemblies in collectible ALC
|
||||||
@@ -1030,16 +1030,18 @@ namespace FlaxEngine.Interop
|
|||||||
FlaxEngine.Json.JsonSerializer.ResetCache();
|
FlaxEngine.Json.JsonSerializer.ResetCache();
|
||||||
|
|
||||||
// Unload the ALC
|
// Unload the ALC
|
||||||
bool unloading = true;
|
if (scriptingAssemblyLoadContext != null)
|
||||||
scriptingAssemblyLoadContext.Unloading += (alc) => { unloading = false; };
|
{
|
||||||
scriptingAssemblyLoadContext.Unload();
|
bool unloading = true;
|
||||||
|
scriptingAssemblyLoadContext.Unloading += (alc) => { unloading = false; };
|
||||||
while (unloading)
|
scriptingAssemblyLoadContext.Unload();
|
||||||
System.Threading.Thread.Sleep(1);
|
|
||||||
|
|
||||||
|
while (unloading)
|
||||||
|
System.Threading.Thread.Sleep(1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
InitScriptingAssemblyLoadContext();
|
InitScriptingAssemblyLoadContext();
|
||||||
DelegateHelpers.InitMethods();
|
DelegateHelpers.InitMethods();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[UnmanagedCallersOnly]
|
[UnmanagedCallersOnly]
|
||||||
|
|||||||
@@ -92,8 +92,6 @@ namespace FlaxEngine.Interop
|
|||||||
System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
|
System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
|
||||||
System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
|
System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
|
||||||
|
|
||||||
InitScriptingAssemblyLoadContext();
|
|
||||||
DelegateHelpers.InitMethods();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if FLAX_EDITOR
|
#if FLAX_EDITOR
|
||||||
|
|||||||
@@ -110,6 +110,9 @@ bool RendererService::Init()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: move it somewhere to game instance class or similar
|
||||||
|
MainRenderTask::Instance = New<MainRenderTask>();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,10 +45,8 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
static void UnloadEngine();
|
static void UnloadEngine();
|
||||||
|
|
||||||
#if USE_EDITOR
|
// Called by Scripting during initialization or in a middle of hot-reload (after unloading modules but before loading them again).
|
||||||
// Called by Scripting in a middle of hot-reload (after unloading modules but before loading them again).
|
static void LoadScriptingAssemblyLoadContext();
|
||||||
static void ReloadScriptingAssemblyLoadContext();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -269,6 +269,8 @@ bool MCore::LoadEngine()
|
|||||||
|
|
||||||
// Prepare managed side
|
// Prepare managed side
|
||||||
CallStaticMethod<void>(GetStaticMethodPointer(TEXT("Init")));
|
CallStaticMethod<void>(GetStaticMethodPointer(TEXT("Init")));
|
||||||
|
MCore::LoadScriptingAssemblyLoadContext();
|
||||||
|
|
||||||
#ifdef MCORE_MAIN_MODULE_NAME
|
#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
|
// 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)));
|
::String flaxLibraryPath(Platform::GetMainDirectory() / TEXT(MACRO_TO_STR(MCORE_MAIN_MODULE_NAME)));
|
||||||
@@ -311,20 +313,16 @@ void MCore::UnloadEngine()
|
|||||||
ShutdownHostfxr();
|
ShutdownHostfxr();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if USE_EDITOR
|
void MCore::LoadScriptingAssemblyLoadContext()
|
||||||
|
|
||||||
void MCore::ReloadScriptingAssemblyLoadContext()
|
|
||||||
{
|
{
|
||||||
// Clear any cached class attributes (see https://github.com/FlaxEngine/FlaxEngine/issues/1108)
|
// Clear any cached class attributes (see https://github.com/FlaxEngine/FlaxEngine/issues/1108)
|
||||||
for (auto e : CachedClassHandles)
|
for (auto e : CachedClassHandles)
|
||||||
e.Value->_attributes.Clear();
|
e.Value->_attributes.Clear();
|
||||||
|
|
||||||
static void* ReloadScriptingAssemblyLoadContextPtr = GetStaticMethodPointer(TEXT("ReloadScriptingAssemblyLoadContext"));
|
static void* LoadScriptingAssemblyLoadContextPtr = GetStaticMethodPointer(TEXT("LoadScriptingAssemblyLoadContext"));
|
||||||
CallStaticMethod<void>(ReloadScriptingAssemblyLoadContextPtr);
|
CallStaticMethod<void>(LoadScriptingAssemblyLoadContextPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
MObject* MCore::Object::Box(void* value, const MClass* klass)
|
MObject* MCore::Object::Box(void* value, const MClass* klass)
|
||||||
{
|
{
|
||||||
static void* BoxValuePtr = GetStaticMethodPointer(TEXT("BoxValue"));
|
static void* BoxValuePtr = GetStaticMethodPointer(TEXT("BoxValue"));
|
||||||
|
|||||||
@@ -717,7 +717,7 @@ void MCore::UnloadEngine()
|
|||||||
|
|
||||||
#if USE_EDITOR
|
#if USE_EDITOR
|
||||||
|
|
||||||
void MCore::ReloadScriptingAssemblyLoadContext()
|
void MCore::LoadScriptingAssemblyLoadContext()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ void MCore::UnloadEngine()
|
|||||||
|
|
||||||
#if USE_EDITOR
|
#if USE_EDITOR
|
||||||
|
|
||||||
void MCore::ReloadScriptingAssemblyLoadContext()
|
void MCore::LoadScriptingAssemblyLoadContext()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class ScriptingService : public EngineService
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ScriptingService()
|
ScriptingService()
|
||||||
: EngineService(TEXT("Scripting"), -20)
|
: EngineService(TEXT("Scripting"), -999)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -703,7 +703,7 @@ void Scripting::Reload(bool canTriggerSceneReload)
|
|||||||
_hasGameModulesLoaded = false;
|
_hasGameModulesLoaded = false;
|
||||||
|
|
||||||
// Release and create a new assembly load context for user assemblies
|
// 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
|
// Give GC a try to cleanup old user objects and the other mess
|
||||||
MCore::GC::Collect();
|
MCore::GC::Collect();
|
||||||
@@ -1091,9 +1091,6 @@ bool initFlaxEngine()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO: move it somewhere to game instance class or similar
|
|
||||||
MainRenderTask::Instance = New<MainRenderTask>();
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user