From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Daniel =?UTF-8?Q?Mart=C3=ADn?= via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#63495: 28.2; menu crashes on macos Date: Thu, 13 Jul 2023 10:47:35 +0200 Message-ID: References: <87bkgjatup.fsf@eshelyaron.com> <87r0pdc9ej.fsf@eshelyaron.com> Reply-To: Daniel =?UTF-8?Q?Mart=C3=ADn?= Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1042"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (darwin) Cc: alan@idiocy.org, obriendavid1@gmail.com, me@eshelyaron.com To: 63495@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jul 13 10:48:29 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 1qJrzw-000AbC-T3 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 13 Jul 2023 10:48:29 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJrzY-0004DN-KA; Thu, 13 Jul 2023 04:48: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 1qJrzW-0004Cw-TC for bug-gnu-emacs@gnu.org; Thu, 13 Jul 2023 04:48:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qJrzW-0007h5-Kh for bug-gnu-emacs@gnu.org; Thu, 13 Jul 2023 04:48:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qJrzW-0003R2-7W for bug-gnu-emacs@gnu.org; Thu, 13 Jul 2023 04:48:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Daniel =?UTF-8?Q?Mart=C3=ADn?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 13 Jul 2023 08:48: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-To: Eshel Yaron via "Bug reports for GNU Emacs, the Swiss army knife of text editors" X-Debbugs-Original-Cc: Alan Third , obriendavid1@gmail.com, Eshel Yaron , 63495@debbugs.gnu.org Original-Received: via spool by 63495-submit@debbugs.gnu.org id=B63495.168923806713090 (code B ref 63495); Thu, 13 Jul 2023 08:48:02 +0000 Original-Received: (at 63495) by debbugs.gnu.org; 13 Jul 2023 08:47:47 +0000 Original-Received: from localhost ([127.0.0.1]:53363 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qJrzH-0003P0-2m for submit@debbugs.gnu.org; Thu, 13 Jul 2023 04:47:47 -0400 Original-Received: from sonic308-17.consmr.mail.ir2.yahoo.com ([77.238.178.145]:45293) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qJrzE-0003O9-0p for 63495@debbugs.gnu.org; Thu, 13 Jul 2023 04:47:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.es; s=s2048; t=1689238058; bh=RU/dR6Q3qdiqrwG3Tbw2UcZrTdDVX4kx+G1Ja94dRpg=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From:Subject:Reply-To; b=Z2djwS/RdWjuyqunW53ktpltG8r49imoofXtsZLgtJZ/ZfKtM8/9LkereYov3IIVIDR6w2UB+EFtm9ylq7Z4UVH3zQouUzyCrwC2khDG4TQ8Csz1T/UROH5+TT0oXfz1IPuOl6D+92QAYjgam8iX7s6hVSDZ2n4ctayCgUHtuPdc40W9SK1gq5Sdykcy+GxieEaVbTESgTnQh7BbIqnF7wtK8LjnffaYaWOx9GkSnxsizP2wAJ+jRJNPyTdGNPK8MtqD1sETDo5U6wpNDA/32mRtadhy++Ooodv8xxVnNrwrpEjpnN2RLCtwveOod40NeSAsseEH7PcGVtMhj83ULQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1689238058; bh=pDces8plHDnQfGr/0fkdzLDdKdscb5/3TnO7JmnnEjo=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=dxNfFtO044GvdCbk9/kDHDheBPZ1iPKkba50RS1C6ghJc4iTfp9j+U5yj5FjeT2MNwh1Mf4oMfl6onZW4YMbBd69zgtuNeofy89dI1EkZB8si01vfj/DEmEnkhrKfSfPViDrcqABuH8cjrPSp7RiquWxrDP3Y27tNfhozDaH8Ax0oMMkrZQlY7YwIXoviiwjrJ/FjnK0rPYgo2K0mDw8W4bMkdqo9ymZJ+spR/eWYxbWhxyxUySnlm6xL32zoAJwhUdKCRklr4RA7T25YVcOarOzYZC3Se234g8eYF0Yv9QxfwLoF5X/MqlRW4nOnlJuSIv11o7UMQB/U01Eq1J54A== X-YMail-OSG: 1BdwyI8VM1nDga1QAZYA70pdv7kj3GpnDOHuSXOQY8U.chgNcpwKK2lcgMGWv4B Dj.DPYBpYh6.zD2n9BwF5IWzyP5JV0UthufHClxcYjUe6iPeZLOTZkbREqnfdwjjr5QpkFnGuWcn T1jNxkIIZxJNLUpsBlYgXZ3UKoomXqRC7laGbgGdmlZHmkudT7VCcwASaagEe5V7GBDUciN2Ch3B .NRLnPjjmmeIvcyo8iVejtc0EqTS4J_KKDoWuSLj5ccwveFpZqK..4IgyTqPbk56D8XrYNs99N1K LDRrYBX55RLRnEQH5dien1PELmK7yoN7UZvuGPTDBYI10n_kxH4n5ZIhX1593.53nVa9XfkzLIjm tFPDer9_KTgzw5M9d0eqwGrpdbBW4yaRC9rI22ueP_IIJ_5yneg37O02VnDKRcc_x1vMdIqM3NFj DHSeel5jnP8gDv9G4244wLyzGlEsfTL_pUAoTY8DdwNVH55susiUsTAwrxArEUXNJ1xSgx0.cqy1 0N_M1hmxX0EGYiNjJodGMlTvzVjinjvzi_KrmBpPatPn1F3GTSYsYFpFSxX5eEyYj0VWxFDsFRx7 XTAxOtVZcqWSU_1i4kUTYHIzQaVwwnPVQXrf_Kjd2rGIujyg0.CJD_ZlczTQ6RsJ1kW7.5k9Y6ls yCqimas2aLI_sgofpbrtZ5iFdhuJ9Gle21_sb21CIg.YjiMDPSOpOT7_IYYs8fhIpEOWv6gHE9Ia CqN5X5Z3GNxMnToIZZVjalhrgJLccR1tfbP83NRnS4eAhVnbmB4Cz0.niu57azM7pDHGai4JcSqd nuhcMtl9lYLyeLqieU.UYOGSYM9K4lpudCYO5Ytd.i X-Sonic-MF: X-Sonic-ID: a014c9a0-480d-4768-9440-b856d8c86767 Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic308.consmr.mail.ir2.yahoo.com with HTTP; Thu, 13 Jul 2023 08:47:38 +0000 Original-Received: by hermes--production-ir2-7858d959bd-m54md (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 57318c72f9760bd6c71ec82dd8435b91; Thu, 13 Jul 2023 08:47:36 +0000 (UTC) In-Reply-To: (Eshel Yaron via's message of "Thu, 13 Jul 2023 09:16:51 +0300") X-Mailer: WebService/1.1.21638 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo 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:265008 Archived-At: Eshel Yaron via "Bug reports for GNU Emacs, the Swiss army knife of text editors" writes: > Alan Third writes: > >> Can you please try this: >> >> modified src/nsmenu.m >> @@ -746,6 +746,8 @@ - (Lisp_Object)runMenuAt: (NSPoint)p forFrame: (struct frame *)f >> NSEvent *e, *event; >> long retVal; >> >> + needsUpdate = NO; >> + >> /* p = [view convertPoint:p fromView: nil]; */ >> p.y = NSHeight ([view frame]) - p.y; >> e = [[view window] currentEvent]; >> >> At a guess, when the menu opens the first thing AppKit does is check if >> it needs updated, and since a new menu starts with needsUpdate=YES, it >> goes ahead and tries to do it, which overwrites some important >> variables from the original "build" of the menu. >> >> The context menu is built and then displayed, as opposed to the >> top-menu that is partially built, then when it's to be displayed is >> updated and filled in. > > I tried it, unfortunately, that doesn't seem to solve the issue. Emacs > still crashes with a similar backtrace: > > * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x3) > frame #0: 0x00000001000af1fd emacs`AREF(array=0x0000000000000000, idx=0) at lisp.h:1941:10 > 1938 AREF (Lisp_Object array, ptrdiff_t idx) > 1939 { > 1940 eassert (0 <= idx && idx < gc_asize (array)); > -> 1941 return XVECTOR (array)->contents[idx]; > 1942 } > 1943 > 1944 INLINE Lisp_Object * > Target 0: (emacs) stopped. > (lldb) bt > * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x3) > * frame #0: 0x00000001000af1fd emacs`AREF(array=0x0000000000000000, idx=0) at lisp.h:1941:10 > frame #1: 0x00000001000b079e emacs`find_and_return_menu_selection(f=0x00000001030b0c30, keymaps=true, client_data=0x0000000110277e60) at menu.c:985:11 > frame #2: 0x000000010037cc1a emacs`-[EmacsMenu runMenuAt:forFrame:keymaps:](self=0x000060000179c9c0, _cmd="runMenuAt:forFrame:keymaps:", p=(x = 2, y = 411), f=0x00000001030b0c30, keymaps=true) at nsmenu.m:769:9 > frame #3: 0x0000000100380ac0 emacs`ns_menu_show(f=0x00000001030b0c30, x=2, y=97, menuflags=1, title=0x0000000102416284, error=0x00007ff7bfefcef0) at nsmenu.m:1069:9 > frame #4: 0x00000001000b23f7 emacs`x_popup_menu_1(position=0x0000000118583f83, menu=0x0000000118587313) at menu.c:1410:17 > frame #5: 0x00000001000b27d2 emacs`Fx_popup_menu(position=0x0000000118583f83, menu=0x0000000118587313) at menu.c:1474:10 > frame #6: 0x000000010024e7d7 emacs`funcall_subr(subr=0x0000000100403c28, numargs=2, args=0x0000000118028188) at eval.c:3049:15 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. 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