[R-SIG-Mac] Help with windowWillClose notification

Duncan Murdoch murdoch.duncan at gmail.com
Thu Sep 4 16:11:19 CEST 2014


I believe I have finally fixed this.  Thanks to Simon who gave the right
solution:  use the windowWillClose notification rather than the dealloc
message.  Thanks also to Neil Tiffin who told me something about how to
implement this, and to Michail Vidiassov who did some nice debugging.

For future reference, here's a summary:

The dealloc method of my object was not called immediately when the
window was closed, so there was a period when rgl thought it had a
window but didn't.  Switching the cleanup code to the windowWillClose
notification fixed this, as I already mentioned.

To add my GLView object as a delegate to receive that notification, I
needed to declare that it supported the NSWindowDelegate protocol when
it was declared, and needed to tell the window to use it as a delegate
via [osxWindow setDelegate:view].

Duncan Murdoch


On 21/08/2014, 8:03 AM, Duncan Murdoch wrote:
> 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:
> 
> library(rgl)
> demo(subdivision)
> 
> #  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