[R-SIG-Mac] Help with windowWillClose notification

Duncan Murdoch murdoch.duncan at gmail.com
Thu Aug 21 14:03:31 CEST 2014

I'm hoping someone here who understands Cocoa programming can help me
with my rgl problems (previously mentioned in the "rgl for R-devel"
thread in July).

To recap:  I had a bug report that this sequence crashes R.app:


#  Close the window by clicking on the X

rgl.demo.subdivision() # This fn was created by the demo

I can track down the problem to see that the cleanup code that was
supposed to be called when the window was closed wasn't called yet,
so rgl tries to put the new plotting results into a window that isn't
there, and dies.

The cleanup code was tied to a -dealloc method on the NSOpenGLView
object; Simon's guess was that the deallocation is asynchronous, and
just hasn't been called yet.  Simon suggested it should be on a
"windowWillClose:" notification.

Okay, so I've tried to do it on the windowWillClose notification, but I
really don't know what I'm doing, so the current version still dies.
Sometimes it gives an R.app error about an "unrecognized selector sent"
 and sometimes it just crashes.  Generally it makes it a little further
than the previous version, letting the second window open and only dying
when I close it.

Does anyone know of any other examples of R packages that open Cocoa
windows, so I could see how they do their cleanup?  Or would anyone like
to volunteer to look at the code and tell me what I'm doing wrong?

Duncan Murdoch

More information about the R-SIG-Mac mailing list