From bc1127da5bb8b1c88e6430e7babb19a4e6d9934b Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Sun, 27 Apr 2014 12:07:54 +0200 Subject: [PATCH] Output error message and abort program when XOpenDisplay() fails Fixes issue #508. When the X11 display could not be opened, the application crashed without notice. Now, a meaningful error message is output to std::err() and std::abort() is called, causing immediate program termination. --- src/SFML/Window/Unix/Display.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/SFML/Window/Unix/Display.cpp b/src/SFML/Window/Unix/Display.cpp index 0a35ee4d7..aad1b2672 100644 --- a/src/SFML/Window/Unix/Display.cpp +++ b/src/SFML/Window/Unix/Display.cpp @@ -25,8 +25,10 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// +#include #include #include +#include namespace @@ -44,7 +46,18 @@ namespace priv Display* OpenDisplay() { if (referenceCount == 0) + { sharedDisplay = XOpenDisplay(NULL); + + // Opening display failed: The best we can do at the moment is to output a meaningful error message + // and cause an abnormal program termination + if (!sharedDisplay) + { + err() << "Failed to open X11 display; make sure the DISPLAY environment variable is set correctly" << std::endl; + std::abort(); + } + } + referenceCount++; return sharedDisplay; }