From 466b55360244421a73092b3f0fea0c707d2c9317 Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@orfeo-toolbox.org>
Date: Mon, 11 May 2009 16:09:29 +0200
Subject: [PATCH] BUG: Fl_Widget destructor generates one last FL_HIDE event
 which causes segmentation fault (maybe because the object is already in its
 desctruction process). Therefore we should avoid to process FL_HIDE events.

---
 Code/Visualization/otbGlWidget.cxx | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/Code/Visualization/otbGlWidget.cxx b/Code/Visualization/otbGlWidget.cxx
index b9d16352b7..4afae9e560 100644
--- a/Code/Visualization/otbGlWidget.cxx
+++ b/Code/Visualization/otbGlWidget.cxx
@@ -37,7 +37,10 @@ GlWidget
 }
 
 GlWidget::~GlWidget()
-{}
+{
+  // Clear registered controller
+  m_Controller = NULL;
+}
 
 void GlWidget::PrintSelf(std::ostream& os, itk::Indent indent) const
 {
@@ -123,15 +126,17 @@ void GlWidget::resize(int x, int y, int w, int h)
 
 int GlWidget::handle(int event)
 {
-  // If there is a controller
-  if(m_Controller.IsNotNull())
-    {
-    return m_Controller->HandleWidgetEvent(m_Identifier,event);
-    }
-  else
+  // Call superclass implementation
+  int resp = Fl_Widget::handle(event);
+  
+  // Check if there is a controller
+  // Avoid processing hide events, since it causes segfault (the
+  // destructor of the Fl class generates hide events).
+  if(m_Controller.IsNotNull() && event != FL_HIDE)
     {
-    return 0;
+    resp = m_Controller->HandleWidgetEvent(m_Identifier,event);
     }
+  return resp;
 }
 
 GlWidget::PointType GlWidget::GetMousePosition()
-- 
GitLab