From 9da0373a92cdd14c08bc19cd9cdf68e2a64d4fb7 Mon Sep 17 00:00:00 2001
From: Jussi Lindgren <jussi.lindgren@inria.fr>
Date: Tue, 17 May 2016 15:28:41 +0200
Subject: [PATCH] Kernel: Disabled aborts on X errors on Fedora

---
 CMakeLists.txt                                |  6 +++--
 .../kernel/player/ovkCOgreVisualisation.cpp   | 24 +++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0e14c401e5..c64dcc1cd6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -112,11 +112,13 @@ ELSEIF(UNIX)
 	endif ()
 
 	if(EXISTS "/etc/debian_version")
-	   set (PLATFORM "Debian")
+		set (PLATFORM "Debian")
+		ADD_DEFINITIONS("-DTARGET_OS_Linux_Debian")
 	endif(EXISTS "/etc/debian_version")
 
 	if(EXISTS "/etc/fedora-release")
-	   set (PLATFORM "Fedora")
+		set (PLATFORM "Fedora")
+		ADD_DEFINITIONS("-DTARGET_OS_Linux_Fedora")
 	endif(EXISTS "/etc/fedora-release")
 
 ELSE(WIN32)
diff --git a/kernel/src/kernel/player/ovkCOgreVisualisation.cpp b/kernel/src/kernel/player/ovkCOgreVisualisation.cpp
index 3f8116d3a6..93b2b12aac 100644
--- a/kernel/src/kernel/player/ovkCOgreVisualisation.cpp
+++ b/kernel/src/kernel/player/ovkCOgreVisualisation.cpp
@@ -11,6 +11,26 @@
 	#include "Overlay/OgreOverlaySystem.h"
 #endif
 
+#if defined(TARGET_OS_Linux_Fedora)
+	// @FIXME this is an awful hack to avoid crashes on our Fedora CI running on CloudStack VM.
+	// It seems that there we get difficult to track X11 errors from inside Ogre that
+	// 1) abort the application
+	// 2) do not seem to appear on a non-VM computer
+	// 3) seem to be of no concern to the automatic testing?
+	// Hence we just specify a dummy error handler until we can solve the problem.
+	#include <stdio.h>
+	#include <X11/Xlib.h>
+
+	static int errorHandlerHack(Display *display, XErrorEvent *event)
+	{
+		(void) fprintf(stderr,
+						"WARNING: Ignored Xlib error: error_code=%d, request_code=%d\n",
+						event->error_code,
+						event->request_code) ;
+		return 0 ;
+	}
+#endif
+
 using namespace std;
 using namespace Ogre;
 using namespace OpenViBE;
@@ -135,6 +155,10 @@ boolean COgreVisualisation::initializeOgre(void) throw (std::exception)
 			//init Ogre w/o creating a default window
 			m_pRoot->initialise(false);
 			m_bOgreInitialised = true;
+
+#if defined(TARGET_OS_Linux_Fedora)
+			XSetErrorHandler(errorHandlerHack);
+#endif
 		}
 
 #if (OGRE_VERSION_MAJOR > 1) || ((OGRE_VERSION_MAJOR == 1) && (OGRE_VERSION_MINOR >= 9))
-- 
GitLab