mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
Remove mono from Glue functions
This commit is contained in:
@@ -36,6 +36,12 @@ static class CoreClrHelper
|
||||
private function void CreateScriptInstanceFunc(UUID entityId, char8* scriptClassName);
|
||||
static CreateScriptInstanceFunc _createScriptInstance;
|
||||
|
||||
private function void ThrowExceptionFunc(char8* message);
|
||||
static ThrowExceptionFunc _throwException;
|
||||
|
||||
private function void RegisterComponentTypeFunc(StringView fullComponentTypeName, function void(UUID entityId) addComponent, function bool(UUID entityId) hasComponent, function void(UUID entityId) removeComponent);
|
||||
static RegisterComponentTypeFunc _registerComponentType;
|
||||
|
||||
public static ScriptFunctionPointers _entityScriptFunctions;
|
||||
|
||||
public static void Init(StringView coreAssemblyPath)
|
||||
@@ -106,6 +112,9 @@ static class CoreClrHelper
|
||||
|
||||
GetFunctionPointerUnmanagedCallersOnly("GlitchyEngine.ScriptGlue, ScriptCore", "CreateScriptInstance", out _createScriptInstance);
|
||||
|
||||
GetFunctionPointerUnmanagedCallersOnly("GlitchyEngine.ScriptGlue, ScriptCore", "ThrowException", out _throwException);
|
||||
GetFunctionPointerUnmanagedCallersOnly("GlitchyEngine.ScriptGlue, ScriptCore", "RegisterComponentType", out _registerComponentType);
|
||||
|
||||
InitEntityFunctions();
|
||||
}
|
||||
|
||||
@@ -182,4 +191,14 @@ static class CoreClrHelper
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
public static void ThrowException(StringView message)
|
||||
{
|
||||
_throwException(message.Ptr);
|
||||
}
|
||||
|
||||
public static void RegisterComponent(StringView fullComponentTypeName, function void(UUID entityId) addComponent, function bool(UUID entityId) hasComponent, function void(UUID entityId) removeComponent)
|
||||
{
|
||||
_registerComponentType(fullComponentTypeName, addComponent, hasComponent, removeComponent);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
using System;
|
||||
using GlitchyEngine.Core;
|
||||
using Mono;
|
||||
|
||||
namespace GlitchyEngine.Scripting;
|
||||
|
||||
|
||||
public class MonoExceptionHelper : RefCounter
|
||||
public class ScriptException : RefCounter
|
||||
{
|
||||
private String _fullName ~ delete _;
|
||||
private String _fullName ~ delete:append _;
|
||||
|
||||
private String _message ~ delete _;
|
||||
private String _message ~ delete:append _;
|
||||
|
||||
private String _stackTrace ~ delete _;
|
||||
private String _stackTrace ~ delete:append _;
|
||||
/// The clean stack trace only contains the Managed Stack (the full trace contains one line for the native-to-managed entry)
|
||||
private StringView _cleanStackTrace;
|
||||
|
||||
private MonoExceptionHelper _innerException ~ _?.ReleaseRef();
|
||||
//TODO
|
||||
//private ScriptException _innerException ~ _?.ReleaseRef();
|
||||
|
||||
public StringView FullName => _fullName;
|
||||
public StringView Message => _message;
|
||||
@@ -23,59 +23,22 @@ public class MonoExceptionHelper : RefCounter
|
||||
public StringView StackTrace => _stackTrace;
|
||||
public StringView CleanStackTrace => _cleanStackTrace;
|
||||
|
||||
public MonoExceptionHelper InnerException => _innerException;
|
||||
//public ScriptException InnerException => _innerException;
|
||||
|
||||
public UUID Instance { get; set; }
|
||||
public UUID EntityId { get; set; }
|
||||
|
||||
public this(MonoException* exception)
|
||||
[AllowAppend]
|
||||
public this(UUID entityId, StringView fullExceptionClassName, StringView message, StringView stackTrace)
|
||||
{
|
||||
MonoObject* exObject = (MonoObject*)exception;
|
||||
String allocFullExceptionClassName = append String(fullExceptionClassName);
|
||||
String allocMessage = append String(fullExceptionClassName);
|
||||
String allocStackTrace = append String(fullExceptionClassName);
|
||||
|
||||
MonoClass* monoClass = Mono.mono_object_get_class(exObject);
|
||||
_fullName = allocFullExceptionClassName;
|
||||
_message = allocMessage;
|
||||
_stackTrace = allocStackTrace;
|
||||
|
||||
StringView classNamespace = .(Mono.mono_class_get_namespace(monoClass));
|
||||
StringView className = .(Mono.mono_class_get_name(monoClass));
|
||||
_fullName = new $"{classNamespace}.{className}";
|
||||
|
||||
GetMessage(exObject, monoClass);
|
||||
|
||||
GetStackTrace(exception);
|
||||
|
||||
GetInnerException(exObject, monoClass);
|
||||
}
|
||||
|
||||
private void GetMessage(MonoObject* exceptionObject, MonoClass* monoClass)
|
||||
{
|
||||
var messageProperty = Mono.mono_class_get_property_from_name(monoClass, "Message");
|
||||
|
||||
MonoObject* message = Mono.mono_property_get_value(messageProperty, exceptionObject, null, null);
|
||||
char8* exMessage = Mono.mono_string_to_utf8((.)message);
|
||||
|
||||
_message = new String(exMessage);
|
||||
|
||||
Mono.mono_free(exMessage);
|
||||
}
|
||||
|
||||
private void GetStackTrace(MonoException* exception)
|
||||
{
|
||||
char8* stacktracePtr = Mono.mono_exception_get_managed_backtrace(exception);
|
||||
_stackTrace = new String(stacktracePtr);
|
||||
|
||||
int entryIndex = _stackTrace.IndexOf("at (wrapper native-to-managed)");
|
||||
|
||||
if (entryIndex != -1)
|
||||
_cleanStackTrace = _stackTrace.Substring(0, entryIndex);
|
||||
else
|
||||
_cleanStackTrace = _stackTrace;
|
||||
}
|
||||
|
||||
private void GetInnerException(MonoObject* exceptionObject, MonoClass* monoClass)
|
||||
{
|
||||
MonoProperty* innerExceptionProperty = Mono.mono_class_get_property_from_name(monoClass, "InnerException");
|
||||
|
||||
MonoObject* innerException = Mono.mono_property_get_value(innerExceptionProperty, exceptionObject, null, null);
|
||||
|
||||
if (innerException != null)
|
||||
_innerException = new MonoExceptionHelper((MonoException*)innerException);
|
||||
// TODO
|
||||
_cleanStackTrace = _stackTrace;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,15 +507,18 @@ static class ScriptEngine
|
||||
return scriptClass;
|
||||
}
|
||||
|
||||
internal static void HandleMonoException(MonoException* exception, UUID entityId)
|
||||
internal static void HandleException()
|
||||
{
|
||||
MonoExceptionHelper wrappedException = new MonoExceptionHelper(exception);
|
||||
|
||||
}
|
||||
|
||||
internal static void LogScriptException(ScriptException exception, UUID entityId)
|
||||
{
|
||||
String entityInfo = scope .();
|
||||
|
||||
if (entityId != .Zero)
|
||||
{
|
||||
wrappedException.Instance = entityId;
|
||||
exception.EntityId = entityId;
|
||||
|
||||
Result<Entity> sourceEntity = Context.GetEntityByID(entityId);
|
||||
|
||||
@@ -525,14 +528,13 @@ static class ScriptEngine
|
||||
}
|
||||
}
|
||||
|
||||
Log.ClientLogger.Error($"Mono Exception \"{wrappedException.FullName}\": \"{wrappedException.Message}\"{entityInfo}\nStackTrace:\n{wrappedException.StackTrace}", wrappedException);
|
||||
|
||||
wrappedException.ReleaseRef();
|
||||
Log.ClientLogger.Error($"Mono Exception \"{exception.FullName}\": \"{exception.Message}\"{entityInfo}\nStackTrace:\n{exception.StackTrace}", exception);
|
||||
}
|
||||
|
||||
|
||||
// TODO: This can go soon?
|
||||
internal static void HandleMonoException(MonoException* exception, ScriptInstance sourceInstance = null)
|
||||
{
|
||||
HandleMonoException(exception, sourceInstance?.EntityId ?? .Zero);
|
||||
//LogScriptException(exception, sourceInstance?.EntityId ?? .Zero);
|
||||
}
|
||||
|
||||
public static void ShowScriptEditor(Entity entity, ScriptComponent* scriptComponent)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user