Bug 15208 - Closing graphic devices window by close button causes R to use 100% CPU if getGraphicsEvent was called before.
Closing graphic devices window by close button causes R to use 100% CPU if ge...
Product: R
Classification: Unclassified
Component: Graphics
R 2.15.2 patched
x86_64/x64/amd64 (64-bit) Linux-Debian
: P5 minor
Assigned To: R-core
Depends on:
  Show dependency treegraph
Reported: 2013-02-15 17:31 UTC by Sebastian Gibb
Modified: 2013-10-23 09:10 UTC (History)
3 users (show)

See Also:

Proposed patch (2.17 KB, patch)
2013-08-19 23:56 UTC, Gabriel Becker
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastian Gibb 2013-02-15 17:31:04 UTC

If close your graphic device window using the close button ("X") provided by your window manager R consumes 100% CPU if you called getGraphicsEvent before.

Steps to Reproduce:

## in R:

## in another terminal

## close the graphic device window by hitting the close button and see "top" output

Actual Results:

R consumes 100% CPU until you hit "Ctrl+C" in the R console.

Expected Results: 

Closing the graphic device window should quit getGraphicsEvent, too.

Build Date & Platform: 

R version 2.15.2 Patched (2013-02-14 r61949)
Platform: x86_64-unknown-linux-gnu (64-bit)

 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [7] LC_PAPER=C                 LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
Comment 1 Gabriel Becker 2013-08-19 23:56:32 UTC
Created attachment 1476 [details]
Proposed patch

Adds a helper function which determines if there are any graphics devices currently listening for events. 

Calls the helper function at each polling step and throws an error if it returns false (no currently open graphics devices are listening for events).

The patch could be changed so that, eg, the helper function is only called when the number of open devices changes, but limited local testing did not indicate any significant performance benefit for doing so, and it made the code less clean.
Comment 2 Gabriel Becker 2013-10-14 20:23:46 UTC
Checking in to see if anyone has had a chance to look at this patch yet. If there is a problem with it I'm happy to submit a revised version.
Comment 3 Duncan Murdoch 2013-10-19 17:56:01 UTC
I just confirmed the bug and Gabriel's patch fixes it, but I don't really like the behaviour.  I see (in OS X) it immediately opens a new window as soon as I close the one that is waiting for the event.  Wouldn't it be better to return NULL, perhaps with a warning, but not with an error?
Comment 4 Duncan Murdoch 2013-10-19 20:33:34 UTC
I'll soon commit a version that returns NULL with no error or warning.
Comment 5 Duncan Murdoch 2013-10-23 09:10:03 UTC
*** Bug 15500 has been marked as a duplicate of this bug. ***