[Rd] Crash when embedding R X11 windows

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Tue Nov 7 15:26:52 CET 2006

Dear R developers,

I've been experimenting with embedding R X11 windows into another application 
using KDE's QXEmbed on linux. Attempting to do so will crash R (with R 2.4.0, 
trunk, and I know the bug has been around in prior versions). I used to think 
this was related to bug #848, but I'm not sure, if / how the solution 
suggested there still applies to current versions of R.

After debugging, I came up with the following patch (in src/modules/X11):

Index: devX11.c
--- devX11.c    (revision 39818)
+++ devX11.c    (working copy)
@@ -586,8 +586,8 @@
     if (event.xany.type == Expose) {
        while(XCheckTypedEvent(display, Expose, &event))
-       XFindContext(display, event.xexpose.window,
-                    devPtrContext, &temp);
+       if (XFindContext(display, event.xexpose.window,
+                    devPtrContext, &temp)) return;
        dd = (NewDevDesc *) temp;
        if (event.xexpose.count == 0)
            do_update = 1;
@@ -595,8 +595,8 @@
     else if (event.type == ConfigureNotify) {
        while(XCheckTypedEvent(display, ConfigureNotify, &event))
-       XFindContext(display, event.xconfigure.window,
-                    devPtrContext, &temp);
+       if (XFindContext(display, event.xconfigure.window,
+                    devPtrContext, &temp)) return;
        dd = (NewDevDesc *) temp;
        xd = (newX11Desc *) dd->deviceSpecific;
        if (xd->windowWidth != event.xconfigure.width ||
@@ -614,8 +614,8 @@
     else if ((event.type == ClientMessage) &&
             (event.xclient.message_type == _XA_WM_PROTOCOLS))
        if (!inclose && event.xclient.data.l[0] == protocol) {
-           XFindContext(display, event.xclient.window,
-                        devPtrContext, &temp);
+           if (XFindContext(display, event.xclient.window,
+                        devPtrContext, &temp)) return;
            dd = (NewDevDesc *) temp;
            KillDevice((DevDesc*) GetDevice(devNumber((DevDesc*) dd)));

I'll have to admit, that I'm mostly clueless as far as X11-programming is 
concerned, so the patch may not be entirely correct. It does fix the crash, 
however, and should be along the right lines. The rationale is, that 
apparently calls to XFindContext() may fail in the context of embedding the 
X11 window. The patch simply checks the return value of XFindContext() for a 
non-zero (i.e. error) value, and in that case drops out of the function.

Does this seem like a valid fix? Should I provide more info?

Thomas Friedrichsmeier
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : https://stat.ethz.ch/pipermail/r-devel/attachments/20061107/acb0b680/attachment.bin 

More information about the R-devel mailing list