diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Menu.java index ecffa1b232d..597dc10f15e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Menu.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Menu.java @@ -264,6 +264,9 @@ void _setVisible (boolean visible) { // Hold on to window in case it is disposed while the popup is open. window.retain(); + // The menu might get disposed in a NS* call below (#922), so better + // keep a reference to `display` here. + final Display display = this.display; // NSMenu processes events on its own while the popup is open. display.sendPreExternalEventDispatchEvent (); NSEvent nsEvent = NSEvent.otherEventWithType(OS.NSApplicationDefined, location, 0, 0.0, window.windowNumber(), window.graphicsContext(), (short)0, 0, 0);