Add FlecsException and abort handling

wip/bindgen
copygirl 2 years ago
parent f77d4e999b
commit a58514d402
  1. 6
      src/gaemstone.ECS/World.cs
  2. 26
      src/gaemstone.Utility/FlecsException.cs

@ -1,4 +1,5 @@
using System; using System;
using gaemstone.Utility;
using static flecs_hub.flecs; using static flecs_hub.flecs;
namespace gaemstone.ECS; namespace gaemstone.ECS;
@ -17,6 +18,11 @@ public unsafe partial class World
public World(params string[] args) public World(params string[] args)
{ {
ecs_os_set_api_defaults();
var api = ecs_os_get_api();
api.abort_ = new FnPtr_Void { Pointer = &FlecsAbortException.Callback };
ecs_os_set_api(&api);
Handle = ecs_init_w_args(args.Length, null); Handle = ecs_init_w_args(args.Length, null);
ChildOf = LookupByPathOrThrow("/flecs/core/ChildOf"); ChildOf = LookupByPathOrThrow("/flecs/core/ChildOf");

@ -0,0 +1,26 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace gaemstone.Utility;
public class FlecsException
: Exception
{
public FlecsException() : base() { }
public FlecsException(string message) : base(message) { }
}
public class FlecsAbortException
: FlecsException
{
private readonly string _stackTrace = new StackTrace(2, true).ToString();
public override string? StackTrace => _stackTrace;
private FlecsAbortException()
: base("Abort was called by flecs") { }
[UnmanagedCallersOnly]
internal static void Callback()
=> throw new FlecsAbortException();
}
Loading…
Cancel
Save