Search code examples
debuggingerror-handlingruntime-errorglfw

How can I force glfwInit() to fail for debugging purposes?


Similar to How can I force SDL_Init() to fail?, I'd like to force glfwInit() to fail to ensure that my error logging code is working properly. How might I do this? I'm on Linux, so Linux-compatible answers are appreciated.


Solution

  • glfwInit() may fail under a number of circumstances

    • If no monitor is connected
    • If you are using a GLFW library compiled for the wrong windowing system (such as Wayland on X11)
    • Dynamic libraries that GLFW depend on failed to be loaded
    • if On Wayland, the compositor does not provide the xdg-shell protocol (replaced wl-shell).
    • etc

    Your best bet is to look into the source code for GLFW. Try to see if you can find anything in _glfwInitX11 or _glfwInitWayland that you can make fail.

    If none of this can be achieved, you could try compiling GLFW yourself, after having rewritten glfwInit to fail for every call.