From dc0927f2b8abea2b10a3c7aa6c20280e229d858c Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Wed, 10 Oct 2012 11:23:31 +0200 Subject: Check if there is an old item before removing it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If something had changed with the menu item before it had actually been originally added to the native menu then this would crash when trying to remove a null item from the native menu. This prevents that from happening. Change-Id: I8d78b5504759225364d5fd051a23c8d6dbd7d1eb Reviewed-by: James Turner Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoamenu.mm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/plugins/platforms/cocoa/qcocoamenu.mm') diff --git a/src/plugins/platforms/cocoa/qcocoamenu.mm b/src/plugins/platforms/cocoa/qcocoamenu.mm index e4baaab3d3..4d35b3202e 100644 --- a/src/plugins/platforms/cocoa/qcocoamenu.mm +++ b/src/plugins/platforms/cocoa/qcocoamenu.mm @@ -218,10 +218,9 @@ void QCocoaMenu::syncMenuItem(QPlatformMenuItem *menuItem) NSMenuItem *oldItem = [m_nativeMenu itemWithTag:(NSInteger) cocoaItem]; if (cocoaItem->sync() != oldItem) { - // native item was changed for some reason - if (!wasMerged) { + // native item was changed for some reason + if (!wasMerged && oldItem) [m_nativeMenu removeItem:oldItem]; - } QCocoaMenuItem* beforeItem = itemOrNull(m_menuItems.indexOf(cocoaItem) + 1); insertNative(cocoaItem, beforeItem); -- cgit v1.2.3