From af8491078dda1fbe02ce269d17262bd3ac26ad8f Mon Sep 17 00:00:00 2001 From: David Elliott Date: Mon, 12 Apr 2004 04:58:32 +0000 Subject: [PATCH] Change m_windowCurrent to m_currentNSWindow such that m_currentNSWindow is never used directly but only to look up the associated wxCocoaNSWindow. If the wxCocoaNSWindow cannot be found later in UpdateMenuBar then it's likely been destroyed but no crash will result as before. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26720 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/mbarman.h | 2 +- src/cocoa/mbarman.mm | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/include/wx/cocoa/mbarman.h b/include/wx/cocoa/mbarman.h index 32c013e0da..70dc7d3d61 100644 --- a/include/wx/cocoa/mbarman.h +++ b/include/wx/cocoa/mbarman.h @@ -64,7 +64,7 @@ protected: // Main menu (if app provides one) wxMenuBar *m_mainMenuBar; wxMenuBarManagerObserver *m_observer; - wxCocoaNSWindow *m_windowCurrent; + WX_NSWindow m_currentNSWindow; }; #endif // wxUSE_MENUS diff --git a/src/cocoa/mbarman.mm b/src/cocoa/mbarman.mm index 77fea84ec6..fa6f666c5f 100644 --- a/src/cocoa/mbarman.mm +++ b/src/cocoa/mbarman.mm @@ -127,7 +127,7 @@ wxMenuBarManager::wxMenuBarManager() m_menuMain = nil; m_mainMenuBarInstalled = true; m_mainMenuBar = NULL; - m_windowCurrent = NULL; + m_currentNSWindow = nil; NSApplication *theNSApplication = wxTheApp->GetNSApplication(); // Create the services menu. @@ -243,7 +243,10 @@ void wxMenuBarManager::InstallMainMenu() void wxMenuBarManager::WindowDidBecomeKey(NSNotification *notification) { - wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]); + /* NOTE: m_currentNSWindow might be destroyed but we only ever use it + to look it up in the hash table. Do not send messages to it. */ + m_currentNSWindow = [notification object]; + wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa(m_currentNSWindow); if(win) InstallMenuBarForWindow(win); else @@ -271,7 +274,6 @@ void wxMenuBarManager::WindowWillClose(NSNotification *notification) void wxMenuBarManager::InstallMenuBarForWindow(wxCocoaNSWindow *win) { wxASSERT(win); - m_windowCurrent = win; wxMenuBar *menubar = win->GetAppMenuBar(win); wxLogTrace(wxTRACE_COCOA,wxT("Found menubar=%p for window=%p."),menubar,win); SetMenuBar(menubar); @@ -279,8 +281,12 @@ void wxMenuBarManager::InstallMenuBarForWindow(wxCocoaNSWindow *win) void wxMenuBarManager::UpdateMenuBar() { - if(m_windowCurrent) - InstallMenuBarForWindow(m_windowCurrent); + if(m_currentNSWindow) + { + wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa(m_currentNSWindow); + if(win) + InstallMenuBarForWindow(win); + } } #endif // wxUSE_MENUS -- 2.47.2