From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#63495: 28.2; menu crashes on macos Date: Thu, 13 Jul 2023 20:41:23 +0100 Message-ID: References: <87bkgjatup.fsf@eshelyaron.com> <87r0pdc9ej.fsf@eshelyaron.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30822"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 63495@debbugs.gnu.org, obriendavid1@gmail.com, me@eshelyaron.com To: Daniel =?UTF-8?Q?Mart=C3=ADn?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jul 13 21:42:20 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qK2Ci-0007kx-BH for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 13 Jul 2023 21:42:20 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qK2CS-0001DJ-OI; Thu, 13 Jul 2023 15:42:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qK2CR-0001Cy-5t for bug-gnu-emacs@gnu.org; Thu, 13 Jul 2023 15:42:03 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qK2CQ-0000oq-UX for bug-gnu-emacs@gnu.org; Thu, 13 Jul 2023 15:42:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qK2CQ-0004M7-IL for bug-gnu-emacs@gnu.org; Thu, 13 Jul 2023 15:42:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 13 Jul 2023 19:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63495 X-GNU-PR-Package: emacs X-Debbugs-Original-Cc: "Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors" , obriendavid1@gmail.com, Eshel Yaron , 63495@debbugs.gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.168927730616720 (code B ref -1); Thu, 13 Jul 2023 19:42:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 13 Jul 2023 19:41:46 +0000 Original-Received: from localhost ([127.0.0.1]:40900 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qK2CA-0004Lc-DJ for submit@debbugs.gnu.org; Thu, 13 Jul 2023 15:41:46 -0400 Original-Received: from lists.gnu.org ([2001:470:142::17]:32920) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qK2C6-0004LM-1L for submit@debbugs.gnu.org; Thu, 13 Jul 2023 15:41:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qK2C0-0001Ae-2X for bug-gnu-emacs@gnu.org; Thu, 13 Jul 2023 15:41:36 -0400 Original-Received: from dane.soverin.net ([2a10:de80:1:4092:b9e9:2296:0:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qK2Bw-0000k2-P3 for bug-gnu-emacs@gnu.org; Thu, 13 Jul 2023 15:41:35 -0400 Original-Received: from smtp.soverin.net (c04smtp-lb01.int.sover.in [10.10.4.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dane.soverin.net (Postfix) with ESMTPS id 4R24jc5KDfzKv; Thu, 13 Jul 2023 19:41:24 +0000 (UTC) Original-Received: from smtp.soverin.net (smtp.soverin.net [10.10.4.100]) by soverin.net (Postfix) with ESMTPSA id 4R24jc3843zHB; Thu, 13 Jul 2023 19:41:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=idiocy.org; s=soverin; t=1689277284; bh=9P/VCBCElWPGdYCQneFwWaCRtAa7UG0CMAPW+SW6CxM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TiHmHTdGPgSbEUT5rp+WhmsdaAdzwD+KWwggnQYeCLYMk/hZcMTLpkv23GC1jyt92 WUKEULMKJ8ALt6DAUuvUHGW/25tdD/niN+QFIGXiv6ryLQrN9oV5dK1OHpB9AZlQmH U/yTMPOJNQeIBgNBT9eveAGNtkjyOKiWkT0KnfsTRrs75G8WzZVtEaE8/ENjb8rQqP qbWGk4CIk6FczOXv3I/tzHKLmeYSF4+XVOdoVvSL8eO6mwv2lMLjTzwkazJDUym9FL ee89ogt/TdkIDgVx9oAkAK8jLwKC1eOPjczkjBPF1JdVbfwh1vg2V3ta3hRGAoUJYX +qc1ekH6TGybA== Original-Received: from alan by faroe.holly.idiocy.org with local (Exim 4.96) (envelope-from ) id 1qK2Bn-0005Jz-2L; Thu, 13 Jul 2023 20:41:23 +0100 X-Soverin-Authenticated: true Mail-Followup-To: Alan Third , Daniel =?UTF-8?Q?Mart=C3=ADn?= , "Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors" , Eshel Yaron , obriendavid1@gmail.com, 63495@debbugs.gnu.org Content-Disposition: inline In-Reply-To: X-CMAE-Score: 0 X-CMAE-Analysis: v=2.4 cv=Mfmq+bzf c=1 sm=1 tr=0 ts=64b05364 a=8nJEP1OIZ-IA:10 a=ws7JD89P4LkA:10 a=sSdNXfNkPd9oIJn9uowA:9 a=7Zwj6sZBwVKJAoWSPKxL6X1jA+E=:19 a=wPNLvfGTeEIA:10 X-Cloudmark-Reporter: XwCdxO2Qeu+pd3DeZ7wndH9OM0E= Received-SPF: pass client-ip=2a10:de80:1:4092:b9e9:2296:0:1; envelope-from=alan@idiocy.org; helo=dane.soverin.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:265046 Archived-At: On Thu, Jul 13, 2023 at 10:47:35AM +0200, Daniel Martín wrote: > One fundamental problem I see with the current logic (or maybe I'm > misunderstanding something) is that, menuNeedsUpdate: is called for both > the menubar and for context menus. However, the ns_update_menubar > routine does not even use the NSMenu that AppKit passed to > menuNeedsUpdate:, it always does this: > > id menu = [NSApp mainMenu]; > > This means that the menu variable will always be the menubar. The code > in ns_update_menubar is only prepared to handle menubar updates, but as > this function updates menu_items, a data structure that is used later by > the context menu in find_and_return_menu_selection, Emacs crashes > because of inconsistencies. Indeed, it looks like context menus don't go anywhere near ns_update_menubar and use similar, but not identical, code in ns_menu_show to construct the menu contents. > Is there any reason we need to do something for context menus in > menuNeedsUpdate:? Alan said that context menus are completely built in > advance (as opposed to the menubar, which is partially built), so I > propose the following patch (which does seem to fix the crash for me and > doesn't cause regressions with the menubar): > > diff --git a/src/nsmenu.m b/src/nsmenu.m > index 2c1f575bdf2..ca367d1abd1 100644 > --- a/src/nsmenu.m > +++ b/src/nsmenu.m > @@ -477,6 +477,16 @@ - (instancetype)initWithTitle: (NSString *)title > call to ns_update_menubar. */ > - (void)menuNeedsUpdate: (NSMenu *)menu > { > + > + /* The context menu is built and then displayed, as opposed to the > + top-menu, which is partially built and then updated and filled in > + when it's time to display it. Therefore, we don't call > + ns_update_menubar if a context menu is active. */ > + if (context_menu_value != 0) > + { > + return; > + } > + > #ifdef NS_IMPL_GNUSTEP > static int inside = 0; > #endif This was going to be my next suggestion, after checking that context_menu_value is always non-zero when using the context menu and zero when using the main menu. Which I haven't done. The next best thing I can think of is to add a flag that marks it specifically as a context menu, or create a specific context menu class that over-rides menuNeedsUpdate, but I dislike the former as we can probably work out it's a context menu in other ways, and the latter is a bit ridiculous. -- Alan Third