fix(scripting): stabilize mono wrapper test teardown
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include <mono/metadata/reflection.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <limits>
|
||||
#include <utility>
|
||||
|
||||
@@ -40,6 +41,7 @@ namespace {
|
||||
struct MonoRootState {
|
||||
MonoDomain* rootDomain = nullptr;
|
||||
bool initialized = false;
|
||||
bool cleanupRegistered = false;
|
||||
};
|
||||
|
||||
enum class ManagedComponentKind {
|
||||
@@ -81,6 +83,19 @@ bool& GetInternalCallRegistrationState() {
|
||||
return registered;
|
||||
}
|
||||
|
||||
void CleanupMonoRootDomainAtExit() {
|
||||
MonoRootState& rootState = GetMonoRootState();
|
||||
if (!rootState.rootDomain) {
|
||||
return;
|
||||
}
|
||||
|
||||
mono_domain_set(rootState.rootDomain, true);
|
||||
mono_jit_cleanup(rootState.rootDomain);
|
||||
rootState.rootDomain = nullptr;
|
||||
rootState.initialized = false;
|
||||
GetInternalCallRegistrationState() = false;
|
||||
}
|
||||
|
||||
std::string BuildFullClassName(const std::string& namespaceName, const std::string& className) {
|
||||
return namespaceName.empty() ? className : namespaceName + "." + className;
|
||||
}
|
||||
@@ -2455,6 +2470,10 @@ bool MonoScriptRuntime::InitializeRootDomain() {
|
||||
mono_domain_set(rootState.rootDomain, true);
|
||||
RegisterInternalCalls();
|
||||
rootState.initialized = true;
|
||||
if (!rootState.cleanupRegistered) {
|
||||
std::atexit(&CleanupMonoRootDomainAtExit);
|
||||
rootState.cleanupRegistered = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user