diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index e8626932..a25f4144 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -5834,6 +5834,11 @@ GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname); * Contexts share resources with the window context and with any other * user context created for that window. * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, + * @ref GLFW_INVALID_VALUE the window parameter is `NULL`, + * @ref GLFW_NO_WINDOW_CONTEXT if the window has no OpenGL or + * OpenGL US context, and @ref GLFW_PLATFORM_ERROR. + * * @param[in] window The Window for which the user context is to be * created. * @return The handle of the user context created, or `NULL` if an diff --git a/src/context.c b/src/context.c index d12ba991..a3057e92 100644 --- a/src/context.c +++ b/src/context.c @@ -767,6 +767,21 @@ GLFWAPI GLFWusercontext* glfwCreateUserContext(GLFWwindow* handle) _GLFW_REQUIRE_INIT_OR_RETURN(NULL); + if (!window) + { + _glfwInputError(GLFW_INVALID_VALUE, + "Cannot create a user context without a valid window handle"); + return NULL; + } + + if (window->context.client == GLFW_NO_API) + { + _glfwInputError(GLFW_NO_WINDOW_CONTEXT, + "Cannot create a user context for a window that has no OpenGL or OpenGL ES context"); + return NULL; + } + + context = _glfwPlatformCreateUserContext(window); return (GLFWusercontext*)context;