From 2c7bccb3a8b6b1c9cb6d4a94a1d61e70fc67a47a Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 6 May 2015 01:38:32 -0400 Subject: [PATCH] Fixed bin destruction on Mac OS X. --- darwin/tab.m | 2 ++ darwin/window.m | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/darwin/tab.m b/darwin/tab.m index 733864df..53e8c622 100644 --- a/darwin/tab.m +++ b/darwin/tab.m @@ -19,6 +19,7 @@ static void destroy(void *data) while ([t->tabview numberOfTabViewItems] != 0) [t->tabview removeTabViewItem:[t->tabview tabViewItemAtIndex:0]]; // then destroy all the bins, destroying children in the process + // the above loop serves the purpose of binSetParent() [t->pages enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) { NSValue *v = (NSValue *) obj; uiContainer *p; @@ -119,6 +120,7 @@ static void tabDeletePage(uiTab *tt, uintmax_t n) binSetMainControl(p, NULL); // remove the bin from the tab view + // this serves the purpose of binSetParent() i = [t->tabview tabViewItemAtIndex:n]; [t->tabview removeTabViewItem:i]; diff --git a/darwin/window.m b/darwin/window.m index 2cc53ebd..3e5749c1 100644 --- a/darwin/window.m +++ b/darwin/window.m @@ -59,8 +59,10 @@ static void windowDestroy(uiControl *c) // first hide ourselves [w->window orderOut:w->window]; // now destroy the bin - // the bin has no parent, so we can just call uiControlDestroy() - // we also don't have to worry about the NSWindow's reference to the content view; that'll be released too + // we need to remove the bin from its parent; this is equivalent to calling binSetParent() + // we do this by changing the content view to a dummy view + // the window will release its reference on the bin now, then it will release its reference on the dummy view when the window itself is finally released + [w->window setContentView:[[NSView alloc] initWithFrame:NSZeroRect]]; uiControlDestroy(uiControl(w->bin)); // now destroy the delegate [w->window setDelegate:nil];