Various fixes for scripting runtime
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
Custom fork: [https://github.com/FlaxEngine/mono](https://github.com/FlaxEngine/mono) with custom features for C# assemblies hot-reloading at runtime without domain unload (more: [https://flaxengine.com/blog/flax-facts-16-scripts-hot-reload/](https://flaxengine.com/blog/flax-facts-16-scripts-hot-reload/)).
|
||||
|
||||
Startup docs about building mono: [https://www.mono-project.com/docs/compiling-mono/](https://www.mono-project.com/docs/compiling-mono/)
|
||||
|
||||
### Notes
|
||||
|
||||
Some useful notes and tips for devs:
|
||||
|
||||
@@ -281,9 +281,10 @@ bool JsonAsset::CreateInstance()
|
||||
|
||||
void JsonAsset::DeleteInstance()
|
||||
{
|
||||
ASSERT_LOW_LAYER(Instance && _dtor);
|
||||
InstanceType = ScriptingTypeHandle();
|
||||
if (!Instance || !_dtor)
|
||||
return;
|
||||
_dtor(Instance);
|
||||
InstanceType = ScriptingTypeHandle();
|
||||
Allocator::Free(Instance);
|
||||
Instance = nullptr;
|
||||
_dtor = nullptr;
|
||||
|
||||
@@ -260,7 +260,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
int32 _firstManagedTypeIndex;
|
||||
int32 _firstManagedTypeIndex = 0;
|
||||
Array<void*> _managedMemoryBlocks;
|
||||
|
||||
public:
|
||||
|
||||
@@ -352,6 +352,7 @@ bool MAssembly::LoadWithImage(const String& assemblyPath)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: load pdbs for custom third-party libs referenced by game assemblies for debugging
|
||||
#if 0
|
||||
// Hack to load debug information for Newtonsoft.Json (enable it to debug C# code of json lib)
|
||||
if (assemblyPath.EndsWith(TEXT("FlaxEngine.CSharp.dll")))
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "MCore.h"
|
||||
#include "MDomain.h"
|
||||
#include "MClass.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
#include "Engine/Core/Types/String.h"
|
||||
#include "Engine/Core/Types/DateTime.h"
|
||||
@@ -353,6 +352,9 @@ bool MCore::LoadEngine()
|
||||
PROFILE_CPU();
|
||||
ASSERT(Globals::MonoPath.IsANSI());
|
||||
|
||||
// Debugging Mono GC
|
||||
//Platform::SetEnvironmentVariable(TEXT("MONO_GC_DEBUG"), TEXT("6:gc-log.txt,check-remset-consistency,nursery-canaries"));
|
||||
|
||||
#if 0
|
||||
// Override memory allocation callback
|
||||
// TODO: use ENABLE_OVERRIDABLE_ALLOCATORS when building Mono to support memory callbacks or use counters for memory profiling
|
||||
|
||||
@@ -114,7 +114,7 @@ MonoString* MUtils::ToString(const String& str)
|
||||
MonoString* MUtils::ToString(const String& str, MonoDomain* domain)
|
||||
{
|
||||
if (str.IsEmpty())
|
||||
return mono_string_empty(mono_domain_get());
|
||||
return mono_string_empty(domain);
|
||||
return mono_string_new_utf16(domain, (const mono_unichar2*)*str, str.Length());
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "ManagedCLR/MMethod.h"
|
||||
#include <ThirdParty/mono-2.0/mono/metadata/mono-debug.h>
|
||||
|
||||
void ManagedSerialization::Serialize(ISerializable::SerializeStream& stream, MonoObject* object)
|
||||
void ManagedSerialization::Serialize(ISerializable::SerializeStream& stream, MObject* object)
|
||||
{
|
||||
if (!object)
|
||||
{
|
||||
@@ -47,7 +47,7 @@ void ManagedSerialization::Serialize(ISerializable::SerializeStream& stream, Mon
|
||||
mono_free(invokeResultChars);
|
||||
}
|
||||
|
||||
void ManagedSerialization::SerializeDiff(ISerializable::SerializeStream& stream, MonoObject* object, MonoObject* other)
|
||||
void ManagedSerialization::SerializeDiff(ISerializable::SerializeStream& stream, MObject* object, MObject* other)
|
||||
{
|
||||
if (!object || !other)
|
||||
{
|
||||
@@ -85,7 +85,7 @@ void ManagedSerialization::SerializeDiff(ISerializable::SerializeStream& stream,
|
||||
mono_free(invokeResultChars);
|
||||
}
|
||||
|
||||
void ManagedSerialization::Deserialize(ISerializable::DeserializeStream& stream, MonoObject* object)
|
||||
void ManagedSerialization::Deserialize(ISerializable::DeserializeStream& stream, MObject* object)
|
||||
{
|
||||
if (!object)
|
||||
return;
|
||||
@@ -98,7 +98,7 @@ void ManagedSerialization::Deserialize(ISerializable::DeserializeStream& stream,
|
||||
Deserialize(StringAnsiView(buffer.GetString(), (int32)buffer.GetSize()), object);
|
||||
}
|
||||
|
||||
void ManagedSerialization::Deserialize(const StringAnsiView& data, MonoObject* object)
|
||||
void ManagedSerialization::Deserialize(const StringAnsiView& data, MObject* object)
|
||||
{
|
||||
const char* str = data.Get();
|
||||
const int32 len = data.Length();
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
/// </summary>
|
||||
/// <param name="stream">The output stream.</param>
|
||||
/// <param name="object">The object to serialize.</param>
|
||||
static void Serialize(ISerializable::SerializeStream& stream, MonoObject* object);
|
||||
static void Serialize(ISerializable::SerializeStream& stream, MObject* object);
|
||||
|
||||
/// <summary>
|
||||
/// Serializes managed object difference to JSON.
|
||||
@@ -26,20 +26,20 @@ public:
|
||||
/// <param name="stream">The output stream.</param>
|
||||
/// <param name="object">The object to serialize.</param>
|
||||
/// <param name="other">The reference object to serialize diff compared to it.</param>
|
||||
static void SerializeDiff(ISerializable::SerializeStream& stream, MonoObject* object, MonoObject* other);
|
||||
static void SerializeDiff(ISerializable::SerializeStream& stream, MObject* object, MObject* other);
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes managed object from the JSON.
|
||||
/// </summary>
|
||||
/// <param name="stream">The input stream.</param>
|
||||
/// <param name="object">The object to deserialize.</param>
|
||||
static void Deserialize(ISerializable::DeserializeStream& stream, MonoObject* object);
|
||||
static void Deserialize(ISerializable::DeserializeStream& stream, MObject* object);
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes managed object from the JSON.
|
||||
/// </summary>
|
||||
/// <param name="data">The input data.</param>
|
||||
/// <param name="object">The object to deserialize.</param>
|
||||
static void Deserialize(const StringAnsiView& data, MonoObject* object);
|
||||
static void Deserialize(const StringAnsiView& data, MObject* object);
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace Flax.Build
|
||||
|
||||
// Prefer installed Roslyn C# compiler over Mono one
|
||||
monoPath = null;
|
||||
cscPath = Path.Combine(Path.GetDirectoryName(Deploy.VCEnvironment.MSBuildPath), "Roslyn", "csc.exe");
|
||||
cscPath = Path.Combine(Path.GetDirectoryName(VCEnvironment.MSBuildPath), "Roslyn", "csc.exe");
|
||||
|
||||
if (!File.Exists(cscPath))
|
||||
{
|
||||
|
||||
@@ -244,6 +244,26 @@ namespace Flax.Build
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the directories inside a directory.
|
||||
/// </summary>
|
||||
/// <param name="directoryPath">The directory path.</param>
|
||||
/// <param name="searchPattern">The custom filter for the directories to delete. Can be used to select files to delete. Null if unused.</param>
|
||||
/// <param name="withSubdirs">if set to <c>true</c> with sub-directories (recursive delete operation).</param>
|
||||
public static void DirectoriesDelete(string directoryPath, string searchPattern = null, bool withSubdirs = true)
|
||||
{
|
||||
if (!Directory.Exists(directoryPath))
|
||||
return;
|
||||
if (searchPattern == null)
|
||||
searchPattern = "*";
|
||||
|
||||
var directories = Directory.GetDirectories(directoryPath, searchPattern, withSubdirs ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
|
||||
for (int i = 0; i < directories.Length; i++)
|
||||
{
|
||||
DirectoryDelete(directories[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The process run options.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user