Bug#639328: pdfscreenshot_event_filter() may cause BadWindow X-Protocol errors.

2011-08-26 Thread Joachim Breitner
Hello Petr,

Am Freitag, den 26.08.2011, 02:07 +0200 schrieb Petr Gajdůšek:
 Package: gtk-vector-screenshot
 Version: 0.3-1
 Severity: important
 Tags: patch
 
 Everytime I open UI (glade) file in anjuta and start dragging a signal 
 from any widget properties panel to the source code, in order to create 
 signal handler, anjuta crashes with BadWindow X-Protocol error.
 
 Sometimes it crashes another application too, i.e. gnome-terminal or 
 gnome-shell.
 
 I experience BadWindow errors from other apps too, but I didn't check if 
 it comes from gtk-vector-screenshot (i.e. gnome-screensaver, gnome-shell).
 
 Debug logs for anjuta attached. The window with id 23070566 for which is 
 XSetTextProperty() from pdfscreenshot_event_filter() called did not 
 exist before crash (dragging start) and did not exists after (checked 
 with xwininfo -int -tree -root)
 
 Patch installing custom error handler ingoring BadWindow errors is attached.
 
 Cheers,
 Petr Gajdůšek

thanks for the report, especially as it comes with a patch!

Do you know why pdfscreenshot_event_filter could cause a BadWindow error
there in the first place? I’d expect that a MapNotify event surely
indicates that the window exists.

Also, do you think there is a reason not to call the original error
handler in silent_error_handler instead of exit()?

Greetings,
Joachim

-- 
Joachim nomeata Breitner
Debian Developer
  nome...@debian.org | ICQ# 74513189 | GPG-Keyid: 4743206C
  JID: nome...@joachim-breitner.de | http://people.debian.org/~nomeata


signature.asc
Description: This is a digitally signed message part


Bug#639328: pdfscreenshot_event_filter() may cause BadWindow X-Protocol errors.

2011-08-26 Thread Petr Gajdůšek

Here is the corrected patch if you haven't corrected it self.

--
Petr Gajdůšek
From 4b85d22b1a650531afd6d6c90d95885a6674f2f6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20Gajd=C5=AF=C5=A1ek?= gajdusek.p...@centrum.cz
Date: Fri, 26 Aug 2011 01:34:37 +0200
Subject: [PATCH] Install error handler ingoring BadWindow X-Protocol errors

---
 gtk-vector-screenshot.c |   16 
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/gtk-vector-screenshot.c b/gtk-vector-screenshot.c
index fd525c8..12f1b8c 100644
--- a/gtk-vector-screenshot.c
+++ b/gtk-vector-screenshot.c
@@ -47,6 +47,8 @@ const gchar *type;
 GdkAtom pdfscreenshot_atom;
 char *supported_str = supported;
 
+XErrorHandler old_handler = (XErrorHandler) 0 ;
+
 /*
  * This function handles the file type combo box callback in the Save As
  * dialogue. I would have expected that such functionality is already provided
@@ -290,6 +292,18 @@ pdfscreenshot_window_create()
 gtk_widget_show_all(GTK_WIDGET(window));
 }
 
+/* 
+ * Ignore all BadWindow errors.
+ */
+int
+silent_error_handler (Display *display, XErrorEvent *error) 
+{
+if (error-error_code != BadWindow) {
+return old_handler (display, error);
+}
+return 0;
+}
+
 GdkFilterReturn
 pdfscreenshot_event_filter (GdkXEvent *xevent, GdkEvent *event, gpointer data)
 {
@@ -299,10 +313,12 @@ pdfscreenshot_event_filter (GdkXEvent *xevent, GdkEvent *event, gpointer data)
 XTextProperty supported;
 XStringListToTextProperty(supported_str, 1, supported);
 
+old_handler = XSetErrorHandler (silent_error_handler);
 XSetTextProperty(ev-xmap.display,
 ev-xmap.window,
 supported,
 gdk_x11_atom_to_xatom(pdfscreenshot_atom));
+(void) XSetErrorHandler (old_handler);
 } else if (ev-type == ClientMessage 
 ev-xclient.message_type == gdk_x11_atom_to_xatom(pdfscreenshot_atom)) {
 if (event-any.window != NULL) {
-- 
1.7.5.4



Bug#639328: pdfscreenshot_event_filter() may cause BadWindow X-Protocol errors.

2011-08-26 Thread Petr Gajdůšek
Dne 27.8.2011 00:33, Petr Gajdůšek napsal(a):
 Here is the corrected patch if you haven't corrected it self.
 

I guess another solution will be in pdfscreenshot_event_filter() to check
if DestroyNotify is already in the queue and do not set the property, if it is.

Something like

if (ev-type == MapNotify) {
XEvent queued_ev;
if (XCheckTypedWindowEvent(ev-xmap.display, ev-xmap.window, 
DestroyNotify, queued_ev)) {
XPutBackEvent(ev-xmap.display, queued_ev);
} else {
XTextProperty supported;
XStringListToTextProperty(supported_str, 1, supported);
XSetTextProperty(ev-xmap.display,
ev-xmap.window,
supported,
gdk_x11_atom_to_xatom(pdfscreenshot_atom));
}
else {
...

But I am not sure if it will prevent all BadWindow errors.

-- 
Cheers
Petr Gajdůšek



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org