Fix engine when used without C# scripting at all

This commit is contained in:
Wojtek Figat
2023-10-11 12:35:27 +02:00
parent cbdd6c4964
commit bc762761dd
6 changed files with 18 additions and 7 deletions

View File

@@ -1,5 +1,8 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
#include "ManagedDictionary.h"
#if USE_CSHARP
Dictionary<ManagedDictionary::KeyValueType, MTypeObject*> ManagedDictionary::CachedDictionaryTypes;
#if !USE_MONO_AOT
ManagedDictionary::MakeGenericTypeThunk ManagedDictionary::MakeGenericType;
@@ -12,3 +15,4 @@ MMethod* ManagedDictionary::CreateInstance;
MMethod* ManagedDictionary::AddDictionaryItem;
MMethod* ManagedDictionary::GetDictionaryKeys;
#endif
#endif

View File

@@ -25,8 +25,8 @@ private:
MonoAssembly* _monoAssembly = nullptr;
MonoImage* _monoImage = nullptr;
#elif USE_NETCORE
StringAnsi _fullname;
void* _handle = nullptr;
StringAnsi _fullname;
#endif
MDomain* _domain;
@@ -50,6 +50,7 @@ public:
/// <param name="name">The assembly name.</param>
MAssembly(MDomain* domain, const StringAnsiView& name);
#if USE_NETCORE
/// <summary>
/// Initializes a new instance of the <see cref="MAssembly"/> class.
/// </summary>
@@ -58,6 +59,7 @@ public:
/// <param name="fullname">The assembly full name.</param>
/// <param name="handle">The managed handle of the assembly.</param>
MAssembly(MDomain* domain, const StringAnsiView& name, const StringAnsiView& fullname, void* handle);
#endif
/// <summary>
/// Finalizes an instance of the <see cref="MAssembly"/> class.

View File

@@ -48,18 +48,22 @@ MAssembly::MAssembly(MDomain* domain, const StringAnsiView& name)
{
}
#if USE_NETCORE
MAssembly::MAssembly(MDomain* domain, const StringAnsiView& name, const StringAnsiView& fullname, void* handle)
: _domain(domain)
: _handle(handle)
, _fullname(fullname)
, _domain(domain)
, _isLoaded(false)
, _isLoading(false)
, _hasCachedClasses(false)
, _reloadCount(0)
, _name(name)
, _fullname(fullname)
, _handle(handle)
{
}
#endif
MAssembly::~MAssembly()
{
Unload();

View File

@@ -2157,7 +2157,7 @@ MObject* MCore::ScriptingObject::CreateScriptingObject(MClass* klass, void* unma
if (managedInstance)
{
// Set unmanaged object handle and id
MCore::ScriptingObject::SetInternalValues(klass, managedInstance, unmanagedPtr, _id);
MCore::ScriptingObject::SetInternalValues(klass, managedInstance, unmanagedPtr, id);
// Initialize managed instance (calls constructor)
MCore::Object::Init(managedInstance);

View File

@@ -1,9 +1,8 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
#include "Engine/Scripting/Types.h"
#if !USE_CSHARP
#include "Engine/Core/Types/Span.h"
#include "Engine/Scripting/ManagedCLR/MCore.h"
#include "Engine/Scripting/ManagedCLR/MDomain.h"
#include "Engine/Scripting/ManagedCLR/MAssembly.h"

View File

@@ -493,9 +493,11 @@ bool Scripting::Load()
flaxEngineModule->TypeNameToTypeIndex["FlaxEngine.Vector3"] = flaxEngineModule->TypeNameToTypeIndex["FlaxEngine.Float3"];
flaxEngineModule->TypeNameToTypeIndex["FlaxEngine.Vector4"] = flaxEngineModule->TypeNameToTypeIndex["FlaxEngine.Float4"];
#endif
#if USE_CSHARP
flaxEngineModule->ClassToTypeIndex[flaxEngineModule->Assembly->GetClass("FlaxEngine.Vector2")] = flaxEngineModule->TypeNameToTypeIndex["FlaxEngine.Vector2"];
flaxEngineModule->ClassToTypeIndex[flaxEngineModule->Assembly->GetClass("FlaxEngine.Vector3")] = flaxEngineModule->TypeNameToTypeIndex["FlaxEngine.Vector3"];
flaxEngineModule->ClassToTypeIndex[flaxEngineModule->Assembly->GetClass("FlaxEngine.Vector4")] = flaxEngineModule->TypeNameToTypeIndex["FlaxEngine.Vector4"];
#endif
#if USE_EDITOR
// Skip loading game modules in Editor on startup - Editor loads them later during splash screen (eg. after first compilation)