Permalink
Browse files

Output error message and abort program when XOpenDisplay() fails

Fixes issue SFML#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.
  • Loading branch information...
Bromeon authored and MarioLiebisch committed Apr 27, 2014
1 parent 255de9d commit 75439f778b6aa848df6597f5376409c94c18a0ac
Showing with 13 additions and 0 deletions.
  1. +13 −0 src/SFML/Window/Unix/Display.cpp
@@ -25,8 +25,10 @@
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Err.hpp>
#include <SFML/Window/Unix/Display.hpp>
#include <cassert>
#include <cstdlib>
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;
}

0 comments on commit 75439f7

Please sign in to comment.