using Brutal.Logging;
namespace Brutal.GlfwApi;
///
/// Handles exceptions that occur during GLFW event processing.
///
public class ExceptionAggregator
{
private readonly List _exceptions = [];
private readonly Lock _lock = new();
///
/// Push an exception to the aggregator.
///
///
///
public void Push(string message, Exception? innerException = null)
{
lock (_lock)
{
_exceptions.Add(new Exception(message, innerException));
}
}
///
/// Checks if there are any exceptions that have been thrown during event processing.
///
///
///
public void CheckExceptions()
{
Exception exception;
lock (_lock)
{
if (_exceptions.Count == 0)
return;
exception = _exceptions.Count == 1 ? _exceptions[0] : new AggregateException(_exceptions.ToArray());
_exceptions.Clear();
}
throw exception;
}
}
///
/// Provides access to the GLFW library.
///
public static partial class Glfw
{
private const string Dll = "glfw";
///
/// The logging category for all GLFW-related logs.
///
public static readonly LogCategory Log = LogCategory.Make("Glfw");
internal static readonly ExceptionAggregator ExceptionAggregator = new();
}