fixed: ati saves our Display* in their libGL, if we close it and do any GL calls...
authorbobo1on1 <bob-nospam-@xbmc.org>
Fri, 18 Feb 2011 18:54:10 +0000 (19:54 +0100)
committertheuni <theuni-nospam-@xbmc.org>
Sat, 19 Feb 2011 16:13:31 +0000 (11:13 -0500)
(cherry picked from commit 402b0ff3a469e24dca37eed7e33defa296423fde)

xbmc/VideoReferenceClock.cpp

index 38407ba..b7eaf75 100644 (file)
@@ -112,6 +112,10 @@ CVideoReferenceClock::CVideoReferenceClock()
   m_TotalMissedVblanks = 0;
   m_UseVblank = false;
   m_Started.Reset();
+
+#if defined(HAS_GLX) && defined(HAS_XRANDR)
+  m_Dpy = NULL;
+#endif
 }
 
 void CVideoReferenceClock::Process()
@@ -214,18 +218,20 @@ bool CVideoReferenceClock::SetupGLX()
   unsigned int GlxTest;
   XSetWindowAttributes Swa;
 
-  m_Dpy = NULL;
   m_vInfo = NULL;
   m_Context = NULL;
   m_Window = NULL;
 
   CLog::Log(LOGDEBUG, "CVideoReferenceClock: Setting up GLX");
 
-  m_Dpy = XOpenDisplay(NULL);
   if (!m_Dpy)
   {
-    CLog::Log(LOGDEBUG, "CVideoReferenceClock: Unable to open display");
-    return false;
+    m_Dpy = XOpenDisplay(NULL);
+    if (!m_Dpy)
+    {
+      CLog::Log(LOGDEBUG, "CVideoReferenceClock: Unable to open display");
+      return false;
+    }
   }
 
   if (!glXQueryExtension(m_Dpy, NULL, NULL))
@@ -405,6 +411,19 @@ void CVideoReferenceClock::CleanupGLX()
 {
   CLog::Log(LOGDEBUG, "CVideoReferenceClock: Cleaning up GLX");
 
+  bool AtiWorkaround = false;
+  const char* VendorPtr = (const char*)glGetString(GL_VENDOR);
+  if (VendorPtr)
+  {
+    CStdString Vendor = VendorPtr;
+    Vendor.ToLower();
+    if (Vendor.compare(0, 3, "ati") == 0)
+    {
+      CLog::Log(LOGDEBUG, "CVideoReferenceClock: GL_VENDOR: %s, using ati dpy workaround", VendorPtr);
+      AtiWorkaround = true;
+    }
+  }
+
   if (m_vInfo)
   {
     XFree(m_vInfo);
@@ -421,7 +440,9 @@ void CVideoReferenceClock::CleanupGLX()
     XDestroyWindow(m_Dpy, m_Window);
     m_Window = NULL;
   }
-  if (m_Dpy)
+
+  //ati saves the Display* in their libGL, if we close it here, we crash
+  if (m_Dpy && !AtiWorkaround)
   {
     XCloseDisplay(m_Dpy);
     m_Dpy = NULL;