From a2e4b5563e153bb62c53866b01c943d83a39b597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Fri, 5 Feb 2021 15:50:50 +0100 Subject: [PATCH] Added Assert to Logger --- GlitchLog/src/DebugLogger.bf | 15 +++++++++++++++ GlitchyEngine/src/Application.bf | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/GlitchLog/src/DebugLogger.bf b/GlitchLog/src/DebugLogger.bf index 95c5b06..b2c8d6a 100644 --- a/GlitchLog/src/DebugLogger.bf +++ b/GlitchLog/src/DebugLogger.bf @@ -25,6 +25,11 @@ namespace GlitchLog public abstract void Assert(bool condition, String error = Compiler.CallerExpression[0], String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum); +#if !DEBUG + [SkipCall] +#endif + public abstract void AssertDebug(bool condition, String error = Compiler.CallerExpression[0], String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum); + public abstract void Log(LogLevel level, StringView format, params Object[] args); } @@ -112,6 +117,16 @@ namespace GlitchLog } } + public override void AssertDebug(bool condition, String error = Compiler.CallerExpression[0], String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum) + { + if (!condition) + { + String failStr = scope .()..AppendF("Assert failed: {} at line {} in {}", error, line, filePath); + InternalLog(.Critical, failStr); + Internal.FatalError(failStr, 1); + } + } + private void InternalLog(LogLevel level, StringView format, params Object[] args) { if(_logLevel > level) diff --git a/GlitchyEngine/src/Application.bf b/GlitchyEngine/src/Application.bf index 6f63430..3f60aa6 100644 --- a/GlitchyEngine/src/Application.bf +++ b/GlitchyEngine/src/Application.bf @@ -29,7 +29,7 @@ namespace GlitchyEngine public this() { - Runtime.Assert(s_Instance == null, "Tried to create a second application."); + Log.EngineLogger.Assert(s_Instance == null, "Tried to create a second application."); s_Instance = this; _window = new Window(.Default);