mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-11-04 12:51:48 +00:00
Fixed exception logging and entity id of messages
This commit is contained in:
@@ -492,19 +492,17 @@ static class ScriptEngine
|
||||
return scriptClass;
|
||||
}
|
||||
|
||||
internal static void LogScriptException(ScriptException exception, UUID entityId)
|
||||
internal static void LogScriptException(ScriptException exception)
|
||||
{
|
||||
String entityInfo = scope .();
|
||||
|
||||
if (entityId != .Zero && Context != null)
|
||||
if (exception.EntityId != .Zero && Context != null)
|
||||
{
|
||||
exception.EntityId = entityId;
|
||||
|
||||
Result<Entity> sourceEntity = Context.GetEntityByID(entityId);
|
||||
Result<Entity> sourceEntity = Context.GetEntityByID(exception.EntityId);
|
||||
|
||||
if (sourceEntity case .Ok(let e))
|
||||
{
|
||||
entityInfo.AppendF($" ({e.Name} | {entityId})");
|
||||
entityInfo.AppendF($" ({e.Name} | {exception.EntityId})");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,44 +1,107 @@
|
||||
using System;
|
||||
using GlitchyEngine.Core;
|
||||
using System.Collections;
|
||||
|
||||
namespace GlitchyEngine.Scripting;
|
||||
|
||||
|
||||
public class ScriptException
|
||||
{
|
||||
private String _fullName ~ delete:append _;
|
||||
|
||||
private String _message ~ delete:append _;
|
||||
|
||||
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;
|
||||
|
||||
//TODO
|
||||
//private ScriptException _innerException ~ _?.ReleaseRef();
|
||||
private StackTrace _stackTrace ~ delete _;
|
||||
|
||||
public StringView FullName => _fullName;
|
||||
public StringView Message => _message;
|
||||
|
||||
public StringView StackTrace => _stackTrace;
|
||||
public StringView CleanStackTrace => _cleanStackTrace;
|
||||
public StackTrace StackTrace => _stackTrace;
|
||||
|
||||
//public ScriptException InnerException => _innerException;
|
||||
|
||||
public UUID EntityId { get; set; }
|
||||
public UUID EntityId { get; private set; }
|
||||
|
||||
[AllowAppend]
|
||||
public this(UUID entityId, StringView fullExceptionClassName, StringView message, StringView stackTrace)
|
||||
public this(UUID entityId, StringView fullExceptionClassName, StringView message, StackTrace ownStackTrace)
|
||||
{
|
||||
String allocFullExceptionClassName = append String(fullExceptionClassName);
|
||||
String allocMessage = append String(message);
|
||||
String allocStackTrace = append String(stackTrace);
|
||||
|
||||
EntityId = entityId;
|
||||
|
||||
_stackTrace = ownStackTrace;
|
||||
|
||||
_fullName = allocFullExceptionClassName;
|
||||
_message = allocMessage;
|
||||
_stackTrace = allocStackTrace;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO
|
||||
_cleanStackTrace = _stackTrace;
|
||||
public class StackFrameInfo
|
||||
{
|
||||
private String _fileName ~ delete:append _;
|
||||
private String _methodSignature ~ delete:append _;
|
||||
public int Line;
|
||||
public int Column;
|
||||
|
||||
public StringView FileName => _fileName;
|
||||
|
||||
public StringView MethodSignature => _methodSignature;
|
||||
|
||||
[AllowAppend]
|
||||
public this(StringView fileName, StringView methodSignature, int line, int column)
|
||||
{
|
||||
String allocFileName = append String(fileName);
|
||||
String allocMethodSignature = append String(methodSignature);
|
||||
|
||||
_fileName = allocFileName;
|
||||
_methodSignature = allocMethodSignature;
|
||||
|
||||
Line = line;
|
||||
Column = column;
|
||||
}
|
||||
|
||||
public override void ToString(String outBuffer)
|
||||
{
|
||||
outBuffer.Append("at ");
|
||||
|
||||
if (MethodSignature.IsEmpty)
|
||||
outBuffer.Append("<unknown>");
|
||||
else
|
||||
outBuffer.Append(MethodSignature);
|
||||
|
||||
outBuffer.Append(" in ");
|
||||
|
||||
if (!_fileName.IsEmpty)
|
||||
outBuffer.AppendF($"{FileName}, line {Line}:{Column}");
|
||||
else
|
||||
outBuffer.Append("<unknown>");
|
||||
}
|
||||
}
|
||||
|
||||
public class StackTrace
|
||||
{
|
||||
private List<StackFrameInfo> _stackFrameInfos ~ DeleteContainerAndItems!(_);
|
||||
|
||||
public Span<StackFrameInfo> Frames => _stackFrameInfos;
|
||||
|
||||
public this(List<StackFrameInfo> ownStackFrameInfos)
|
||||
{
|
||||
_stackFrameInfos = ownStackFrameInfos;
|
||||
}
|
||||
|
||||
[Commutable]
|
||||
public static bool operator ==(StackTrace a, StackTrace b)
|
||||
{
|
||||
if (a == null || b == null)
|
||||
return a === b;
|
||||
|
||||
return a._stackFrameInfos.Equals(b._stackFrameInfos);
|
||||
}
|
||||
|
||||
public override void ToString(String outBuffer)
|
||||
{
|
||||
for (let frame in _stackFrameInfos)
|
||||
{
|
||||
frame.ToString(outBuffer);
|
||||
outBuffer.Append('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,19 +28,29 @@ using internal GlitchyEngine.Content;
|
||||
// TODO: Move to logger?
|
||||
class MessageOrigin
|
||||
{
|
||||
private UUID _entityId;
|
||||
private String _fileName ~ delete:append _;
|
||||
private String _callerMemberName ~ delete:append _;
|
||||
private int _lineNumber;
|
||||
private int _columnNumber;
|
||||
|
||||
public UUID EntityId => _entityId;
|
||||
public StringView FileName => _fileName;
|
||||
public StringView CallerMemberName => _callerMemberName;
|
||||
public int LineNumber => _lineNumber;
|
||||
public int ColumnNumber => _columnNumber;
|
||||
|
||||
[AllowAppend]
|
||||
public this(StringView fileName, int lineNumber)
|
||||
public this(UUID entityId, StringView fileName, StringView callerMemberName, int lineNumber, int columnNumber)
|
||||
{
|
||||
String file = append String(fileName);
|
||||
String caller = append String(callerMemberName);
|
||||
|
||||
_entityId = entityId;
|
||||
_fileName = file;
|
||||
_callerMemberName = caller;
|
||||
_lineNumber = lineNumber;
|
||||
_columnNumber = columnNumber;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,7 +455,7 @@ static class ScriptGlue
|
||||
#region Log
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
static void Log_LogMessage(LogLevel logLevel, StringView messagePtr, StringView fileNamePtr, int lineNumber)
|
||||
static void Log_LogMessage(LogLevel logLevel, UUID entityId, StringView messagePtr, StringView fileNamePtr, StringView callerMemberNamePtr, int lineNumber, int columnNumber)
|
||||
{
|
||||
String escapedMessage = new:ScopedAlloc! String(messagePtr);
|
||||
|
||||
@@ -455,9 +465,7 @@ static class ScriptGlue
|
||||
|
||||
if (!fileNamePtr.IsEmpty)
|
||||
{
|
||||
String fileName = new:ScopedAlloc! String(fileNamePtr);
|
||||
|
||||
MessageOrigin messageOrigin = scope MessageOrigin(fileName, lineNumber);
|
||||
MessageOrigin messageOrigin = scope MessageOrigin(entityId, fileNamePtr, callerMemberNamePtr, lineNumber, columnNumber);
|
||||
|
||||
Log.ClientLogger.Log((LogLevel)logLevel, escapedMessage, messageOrigin);
|
||||
}
|
||||
@@ -467,11 +475,27 @@ static class ScriptGlue
|
||||
}
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
static void Log_LogException(UUID entityId, StringView fullExceptionClassName, StringView exceptionMessage, StringView stackTrace)
|
||||
[Ordered]
|
||||
public struct GlueStackFrameInfo
|
||||
{
|
||||
ScriptException exception = new ScriptException(entityId, fullExceptionClassName, exceptionMessage, stackTrace);
|
||||
ScriptEngine.LogScriptException(exception, entityId);
|
||||
public StringView FileName;
|
||||
public StringView MethodSignature;
|
||||
public int32 Line;
|
||||
public int32 Column;
|
||||
}
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
static void Log_LogException(UUID entityId, StringView fullExceptionClassName, StringView exceptionMessage, GlueStackFrameInfo* stackFrameInfos, int32 stackFrameCount)
|
||||
{
|
||||
List<StackFrameInfo> frames = new .(stackFrameCount);
|
||||
|
||||
for (GlueStackFrameInfo frameInfo in Span<GlueStackFrameInfo>(stackFrameInfos, stackFrameCount))
|
||||
{
|
||||
frames.Add(new StackFrameInfo(frameInfo.FileName, frameInfo.MethodSignature, frameInfo.Line, frameInfo.Column));
|
||||
}
|
||||
|
||||
ScriptException exception = new ScriptException(entityId, fullExceptionClassName, exceptionMessage, new StackTrace(frames));
|
||||
ScriptEngine.LogScriptException(exception);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -642,7 +666,7 @@ static class ScriptGlue
|
||||
|
||||
#endregion
|
||||
|
||||
#region TransformComponen
|
||||
#region TransformComponent
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
static EngineResult Transform_GetParent(UUID entityId, out UUID parentId)
|
||||
@@ -966,7 +990,7 @@ static class ScriptGlue
|
||||
|
||||
#endregion Rigidbody2D
|
||||
|
||||
#region Camer
|
||||
#region Camera
|
||||
|
||||
[RegisterCall, CallingConvention(.Cdecl)]
|
||||
static void Camera_GetProjectionType(UUID entityId, out SceneCamera.ProjectionType projectionType)
|
||||
|
||||
Reference in New Issue
Block a user