glfw: Leftover errdefer in glfw.init #826

Closed
opened 2023-06-26 22:57:34 +00:00 by Luexa · 1 comment
Luexa commented 2023-06-26 22:57:34 +00:00 (Migrated from github.com)

github.com/hexops/mach@5cf18801a1/libs/glfw/src/main.zig (L92-L98)

The errdefer here will not trigger as glfw.init() returns a bool, not an error union. This means that the assert will be incorrectly triggered if glfw.init() is invoked after a previous invocation of glfw.init() returned false. Some other mechanism is required to unset the debug value.

Also, glfw.terminate() shouldn't need to assert that GLFW is initialized, as glfwTerminate() has well defined behavior of doing nothing when glfwInit() has not returned successfully. Of course, the debug value should still be unset on glfw.terminate().

https://github.com/hexops/mach/blob/5cf18801a180859bda446347f424f4af9ff23430/libs/glfw/src/main.zig#L92-L98 The `errdefer` here will not trigger as `glfw.init()` returns a bool, not an error union. This means that the assert will be incorrectly triggered if `glfw.init()` is invoked after a previous invocation of `glfw.init()` returned false. Some other mechanism is required to unset the debug value. Also, `glfw.terminate()` shouldn't need to assert that GLFW is initialized, as `glfwTerminate()` has well defined behavior of doing nothing when `glfwInit()` has not returned successfully. Of course, the debug value should still be unset on `glfw.terminate()`.
emidoots commented 2024-07-08 13:04:26 +00:00 (Migrated from github.com)
https://github.com/hexops/mach/issues/1166#issuecomment-2212962722
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
hexops/mach#826
No description provided.