DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2385
Version: 1.3-current


If the right circumstances are present (for some reason, maximus causes
this frequently with my FLTK app), the window XID passed in the XEvent
struct for the "ReparentNotify" handler may be invalid (destroyed) before
we can call XTranslateCoords.  If this is the case, we get a BadWindow
error and the apps bombs out.  Like Fl_Read_Image, we should anticipate
this might happen and if so ignore the event gracefully.  This can be done
by setting a custom XErrorHandler before the call, and using it to
determine whether the call was successful.  See the patch, attached.

P.S. Something I don't understand is why the default FLTK X error handler
isn't set at this point anyway.  If it were, I don't believe we would have
an error.  This may be something I'm doing in my app though, but either
way, this patch should make FLTK a bit more resilient.


Link: http://www.fltk.org/str.php?L2385
Version: 1.3-current
Index: Fl_x.cxx
===================================================================
--- Fl_x.cxx    (revision 7652)
+++ Fl_x.cxx    (working copy)
@@ -793,6 +793,30 @@
 static char unknown[] = "<unknown>";
 const int unknown_len = 10;
 
+/* Seb was here - avoid ReparentNotify crash which seems to appear
+ * if Maximus is running on Ubuntu dists. */
+
+extern "C" {
+       
+       int _xerror = 0;
+       
+       static int _ignorexevents( Display *display, XErrorEvent *event ){
+               _xerror = 1;
+               return 0;
+       }
+       
+       inline static XErrorHandler CatchXException() {
+               _xerror = 0;
+               return _ignorexevents;
+       }
+       
+       inline static int WasXExceptionRaised() {
+               return _xerror;
+       }
+
+}
+       
+
 int fl_handle(const XEvent& thisevent)
 {
   XEvent xevent = thisevent;
@@ -1350,17 +1374,24 @@
   case ReparentNotify: {
     int xpos, ypos;
     Window junk;
-
+    
+    XErrorHandler oldhandler = XSetErrorHandler( CatchXException() );
+    
     //ReparentNotify gives the new position of the window relative to
     //the new parent. FLTK cares about the position on the root window.
     XTranslateCoordinates(fl_display, xevent.xreparent.parent,
                           XRootWindow(fl_display, fl_screen),
                           xevent.xreparent.x, xevent.xreparent.y,
                           &xpos, &ypos, &junk);
-
-    // tell Fl_Window about it and set flag to prevent echoing:
-    resize_bug_fix = window;
-    window->position(xpos, ypos);
+    
+    XSetErrorHandler( oldhandler );
+    
+    if( !WasXExceptionRaised() ){
+        // tell Fl_Window about it and set flag to prevent echoing:
+        resize_bug_fix = window;
+        window->position(xpos, ypos);
+    }
+    
     break;
     }
   }
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to