From 71cef1de3f9c0e938f081dbc656b06e68de5822a Mon Sep 17 00:00:00 2001
From: Connor McLaughlin <stenzek@gmail.com>
Date: Wed, 15 Jul 2020 15:50:30 +1000
Subject: [PATCH] GL/ContextGLX: Add additional logging

---
 src/common/gl/context_glx.cpp | 9 ++++++---
 src/common/gl/x11_window.cpp  | 8 ++++++++
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/common/gl/context_glx.cpp b/src/common/gl/context_glx.cpp
index 7a8a1af22..a46037b75 100644
--- a/src/common/gl/context_glx.cpp
+++ b/src/common/gl/context_glx.cpp
@@ -15,6 +15,9 @@ ContextGLX::~ContextGLX()
   if (m_context)
     glXDestroyContext(GetDisplay(), m_context);
 
+  if (m_vi)
+    XFree(m_vi);
+
   if (m_libGL_handle)
     dlclose(m_libGL_handle);
 }
@@ -242,14 +245,14 @@ bool ContextGLX::CreateWindow(int screen)
     return false;
   }
 
-  const XVisualInfo* vi = glXGetVisualFromFBConfig(GetDisplay(), m_fb_config);
-  if (!vi)
+  m_vi = glXGetVisualFromFBConfig(GetDisplay(), m_fb_config);
+  if (!m_vi)
   {
     Log_ErrorPrintf("glXGetVisualFromFBConfig() failed");
     return false;
   }
 
-  return m_window.Create(GetDisplay(), static_cast<Window>(reinterpret_cast<uintptr_t>(m_wi.window_handle)), vi);
+  return m_window.Create(GetDisplay(), static_cast<Window>(reinterpret_cast<uintptr_t>(m_wi.window_handle)), m_vi);
 }
 
 bool ContextGLX::CreateAnyContext(GLXContext share_context, bool make_current)
diff --git a/src/common/gl/x11_window.cpp b/src/common/gl/x11_window.cpp
index 1913dd54f..d62273a8e 100644
--- a/src/common/gl/x11_window.cpp
+++ b/src/common/gl/x11_window.cpp
@@ -1,6 +1,9 @@
 #include "x11_window.h"
 #include "../assert.h"
+#include "../log.h"
 #include <cstdio>
+Log_SetChannel(X11Window);
+
 namespace GL {
 X11Window::X11Window() = default;
 
@@ -87,6 +90,11 @@ X11InhibitErrors::~X11InhibitErrors()
 
 int X11InhibitErrors::ErrorHandler(Display* display, XErrorEvent* ee)
 {
+  char error_string[256] = {};
+  XGetErrorText(display, ee->error_code, error_string, sizeof(error_string));
+  Log_WarningPrintf("X11 Error: %s (Error %u Minor %u Request %u)", error_string, ee->error_code, ee->minor_code,
+                    ee->request_code);
+
   s_current_error_inhibiter->m_had_error = true;
   return 0;
 }