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.
This commit is contained in:
Jan Haller 2014-04-27 12:07:54 +02:00
parent 5912d205d3
commit bc1127da5b

View File

@ -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;
}