Skip to content

Commit

Permalink
[GL] Add proper exception type
Browse files Browse the repository at this point in the history
F# exceptions are awkward and printed by just listing all data.

See: dotnet/fsharp#3327
  • Loading branch information
hyazinthh committed Jun 13, 2024
1 parent 09e8e5f commit d6bbc53
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/Aardvark.Rendering.GL/Core/DebugOutput.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,34 @@ open System.Runtime.InteropServices
open OpenTK.Graphics
open OpenTK.Graphics.OpenGL4
open Aardvark.Base
open Aardvark.Rendering
open Aardvark.Rendering.GL

type OpenGLException =
inherit Exception
val Error: ErrorCode

new () =
OpenGLException("An error occurred.")

new (message: string) =
{ inherit Exception(message); Error = ErrorCode.NoError }

new (message: string, innerException: exn) =
{ inherit Exception(message, innerException); Error = ErrorCode.NoError }

new (error: ErrorCode) =
OpenGLException(error, null, null)

new (error: ErrorCode, message: string) =
OpenGLException(error, message, null)

new (error: ErrorCode, message: string, innerException: exn) =
let message = if String.IsNullOrEmpty message then "An error occurred" else message
{ inherit Exception($"{message} (Error: {error})", innerException); Error = error }

[<AutoOpen>]
module Error =

exception OpenGLException of ec : ErrorCode * msg : string with
override x.Message = $"{x.msg} (Error: {x.ec})"

type GL with
static member private Check(str, throwOnError) =
let err = GL.GetError()
Expand Down

0 comments on commit d6bbc53

Please sign in to comment.