diff --git a/examples/opengl/triangle/platform/platform_rgfw.cpp b/examples/opengl/triangle/platform/platform_rgfw.cpp index f37d2407..4275bd2f 100644 --- a/examples/opengl/triangle/platform/platform_rgfw.cpp +++ b/examples/opengl/triangle/platform/platform_rgfw.cpp @@ -10,10 +10,34 @@ #include #include +#if defined(__linux__) +#include +static bool platformHasDisplay() { + // RGFW workaround: RGFW indiscriminately passes XOpenDisplay(0) unchecked + // to X11 functions like XCreateWindow(), which will lead to SIGSEGV. + Display* display = XOpenDisplay(0); + if (display == nullptr) { + fprintf(stderr, "ERROR: failed to open X11 display (is $DISPLAY set?)\n"); + return false; + } + XCloseDisplay(display); + return true; +} +#else +static bool platformHasDisplay() { + return true; +} +#endif + static RGFW_window* sWin = nullptr; static std::chrono::steady_clock::time_point sStartTime; bool platformInit(int width, int height, const char* title) { + if (!platformHasDisplay()) { + fprintf(stderr, "ERROR: no display found\n"); + return false; + } + RGFW_glHints* hints = RGFW_getGlobalHints_OpenGL(); hints->major = 3; hints->minor = 3; @@ -22,7 +46,7 @@ bool platformInit(int width, int height, const char* title) { sWin = RGFW_createWindow(title, 0, 0, width, height, RGFW_windowCenter | RGFW_windowOpenGL); if (!sWin) { - fprintf(stderr, "RGFW: failed to create window\n"); + fprintf(stderr, "ERROR: failed to create window\n"); return false; } RGFW_window_makeCurrentContext_OpenGL(sWin);