I am using the OpenGL callback function (see `glDebugMessageCallback`). It is working correctly and prints out the information as expected.
I would like to raise an exception in this call so that I can force an error and get a stack trace. I have:
proc glDebugOutput*(
source: GLenum_t,
ofType: GLenum_t,
id: GLuint_t,
severity: GLenum_t,
length: GLsizei_t,
message: cstring,
userParam: pointer) {.cdecl, raises: [Exception].} =
echo "---------------"
echo fmt"Debug message ({$id}): {message}"
...
...
raise newException(Exception, "glDebugOutput raised exception") When I test this code, the first time the call back is executed, the error message is printed. The application keeps running and thereafter only "---------------" is printed.
My question is: is this possible? Need I do something else to 1) force the application to terminate and 2) get a stack trace.
TIA
- Nim exceptions not compatible with OpenGL.
I had assumed that since Nim transpiled to C this would not be an issue. I don't know the details, but this seems to be the most likely cause.
- Some threading issue.
I am using glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS), so this should not be an problem according to the comments I found.
- Flushing.
I tried flushing and no changes occurred.
- Message is not NULL terminated.
Here is the strange thing. I did some experiments and if I simply echo the message (with or without fmt), the output keeps working as expected. However, as soon as I output any of the other variables, all output from there on disappears (see examples in the end). It seems likely that the call after the exception is not working correctly (terminates?). Maybe the message may still appear because its buffer was allocated in heap and not stack. The wonder is that this does not fail with some segmentation fault.
I have also noticed that when the application terminates Nim reports:
/home/hmf_x/VSCodeProjects/nim_learn/funim_glfw/src/examples/anton_tutorial/vertex_buffer_objects_1.nim(467) vertex_buffer_objects_1
/home/hmf_x/VSCodeProjects/nim_learn/funim_glfw/src/examples/anton_tutorial/vertex_buffer_objects_1.nim(450) main
/home/hmf_x/VSCodeProjects/nim_learn/funim_glfw/src/examples/anton_tutorial/debug.nim(196) glDebugOutput
Error: unhandled exception: glDebugOutput raised exception [Exception]
which does show the correct stack trace.
So my question is, does/should Nim exceptions work on C invocked callbacks in general? Here I would assume this debug callback is doing some unexpected magic.
I final comment is that:
echo getStackTrace()
quit(EXIT_FAILURE)
produces the correct stacktrace, so I will stick to this and assume the application will always fail.
TIA,
Some examples:
echo "---------------"
# echo fmt"Debug message ({$id}): {message}"
echo "???????"
echo fmt"{message}"
echo source
echo "!!!!!!!"
results in:
---------------
???????
GL_INVALID_ENUM in glDrawArrays
33350
!!!!!!!
Source: API
Type: Error
Severity: high
---------------
???????
GL_INVALID_ENUM in glDrawArrays
---------------
???????
GL_INVALID_ENUM in glDrawArrays
This
echo "---------------"
# echo fmt"Debug message ({$id}): {message}"
echo source
echo "???????"
echo fmt"{message}"
echo "!!!!!!!"
results in:
---------------
33350
???????
GL_INVALID_ENUM in glDrawArrays
!!!!!!!
Source: API
Type: Error
Severity: high
---------------
---------------
---------------
---------------Nim has its own (inefficient) backtrace implementation which typically is not compatible with C libraries.
You might have more luck if you compile with https://github.com/status-im/nim-libbacktrace and --debugger:native.