X11: Don't call any X11 functions on fatal error

If X11 functions are called after a fatal error then it just triggers the fatal
error handler again eventually leading to stack overflow.
This commit is contained in:
phantom10111
2024-05-11 09:46:26 -07:00
committed by teejusb
parent 3f8a7f5fd3
commit bbf556450d
4 changed files with 10 additions and 2 deletions
+2 -2
View File
@@ -138,7 +138,7 @@ static DeviceButton XSymToDeviceButton( int key )
InputHandler_X11::InputHandler_X11() InputHandler_X11::InputHandler_X11()
{ {
if( Dpy == nullptr || Win == None ) if( Dpy == nullptr || Win == None )
return; return;
XWindowAttributes winAttrib; XWindowAttributes winAttrib;
@@ -154,7 +154,7 @@ InputHandler_X11::InputHandler_X11()
InputHandler_X11::~InputHandler_X11() InputHandler_X11::~InputHandler_X11()
{ {
if( Dpy == nullptr || Win == None ) if( Dpy == nullptr || Win == None || FatalError )
return; return;
// TODO: Determine if we even need to set this back (or is the window // TODO: Determine if we even need to set this back (or is the window
// destroyed just after this?) // destroyed just after this?)
@@ -92,6 +92,9 @@ LowLevelWindow_X11::LowLevelWindow_X11()
LowLevelWindow_X11::~LowLevelWindow_X11() LowLevelWindow_X11::~LowLevelWindow_X11()
{ {
if( FatalError )
return;
// Reset the display // Reset the display
if( !m_bWasWindowed ) if( !m_bWasWindowed )
{ {
+2
View File
@@ -11,6 +11,7 @@
Display *X11Helper::Dpy = nullptr; Display *X11Helper::Dpy = nullptr;
Window X11Helper::Win = None; Window X11Helper::Win = None;
bool X11Helper::FatalError = false;
static int ErrorCallback( Display*, XErrorEvent* ); static int ErrorCallback( Display*, XErrorEvent* );
static int FatalCallback( Display* ); static int FatalCallback( Display* );
@@ -160,6 +161,7 @@ int ErrorCallback( Display *d, XErrorEvent *err )
int FatalCallback( Display *d ) int FatalCallback( Display *d )
{ {
X11Helper::FatalError = true;
RageException::Throw( "Fatal I/O error communicating with X server." ); RageException::Throw( "Fatal I/O error communicating with X server." );
} }
+3
View File
@@ -24,6 +24,9 @@ namespace X11Helper
// The Window used by LowLevelWindow_X11 as the main window. // The Window used by LowLevelWindow_X11 as the main window.
extern Window Win; extern Window Win;
// Set to true when fatal error has occured and no further X11 calls should be made.
extern bool FatalError;
// (Re)create the Window win. // (Re)create the Window win.
bool MakeWindow( Window &win, int screenNum, int depth, Visual *visual, bool MakeWindow( Window &win, int screenNum, int depth, Visual *visual,
int width, int height, bool overrideRedirect ); int width, int height, bool overrideRedirect );