From 7a8a959ea8bb256b400ea25cbd5ab0b1651348e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bu=C4=9Fra=20Kadirhan?= <54780023+bugravirgomercury@users.noreply.github.com> Date: Sun, 3 Apr 2022 19:02:08 +0300 Subject: [PATCH] Closes #2071, implementing glfwGetErrorDescription --- include/GLFW/glfw3.h | 23 +++++++++++++++++++++++ src/init.c | 17 +++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 3f320065..9f3d75a4 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -2364,6 +2364,29 @@ GLFWAPI const char* glfwGetVersionString(void); */ GLFWAPI int glfwGetError(const char** description); +/*! @brief Returns the description for a specific error code. + * + * @param[in] code The error code whose description is requested. + * @return The error description pointer belonging to specified error code, or NULL if error code is not found. + * + * @errors None. + * + * @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 library is terminated. + * + * @remark This function may be called before @ref glfwInit. + * + * @thread_safety This function may be called from any thread. + * + * @sa @ref error_handling + * @sa @ref glfwGetError + * + * @since Added in version 3.3.7. + * + * @ingroup init + */ +GLFWAPI const char* glfwGetErrorDescription(int code); + /*! @brief Sets the error callback. * * This function sets the error callback, which is called with an error code diff --git a/src/init.c b/src/init.c index 9f0316ac..f2046a64 100644 --- a/src/init.c +++ b/src/init.c @@ -484,6 +484,23 @@ GLFWAPI int glfwGetError(const char** description) return code; } +GLFWAPI const char* glfwGetErrorDescription(int code) +{ + _GLFWerror* error; + + error = _glfw.errorListHead; + + while (error) + { + if (error->code == code) + return error->description; + + error = error->next; + } + + return NULL; +} + GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun) { _GLFW_SWAP(GLFWerrorfun, _glfwErrorCallback, cbfun);