glfw: add getErrorString() to access the current error description
This commit is contained in:
parent
6f3864c1f9
commit
27146af8ce
1 changed files with 25 additions and 0 deletions
|
|
@ -127,6 +127,27 @@ pub inline fn getError() Error!void {
|
|||
return convertError(c.glfwGetError(null));
|
||||
}
|
||||
|
||||
/// Returns and clears the last error description for the calling thread.
|
||||
///
|
||||
/// This function returns a UTF-8 encoded human-readable description of the last error that occured
|
||||
/// on the calling thread. If no error has occurred since the last call, it returns null.
|
||||
///
|
||||
/// @pointer_lifetime The returned string is allocated and freed by GLFW. You should not free it
|
||||
/// yourself. It is guaranteed to be valid only until the next error occurs or the library is
|
||||
/// terminated.
|
||||
///
|
||||
/// @remark This function may be called before @ref glfwInit.
|
||||
///
|
||||
/// @thread_safety This function may be called from any thread.
|
||||
pub inline fn getErrorString() ?[]const u8 {
|
||||
var desc: [*c]const u8 = null;
|
||||
const error_code = c.glfwGetError(&desc);
|
||||
convertError(error_code) catch {
|
||||
return mem.sliceTo(desc, 0);
|
||||
};
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Sets the error callback.
|
||||
///
|
||||
/// This function sets the error callback, which is called with an error code
|
||||
|
|
@ -184,3 +205,7 @@ test "errorCallback" {
|
|||
};
|
||||
setErrorCallback(TestStruct.callback);
|
||||
}
|
||||
|
||||
test "error string" {
|
||||
try testing.expect(getErrorString() == null);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue