all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Third <alan@idiocy.org>
To: "Daniel Martín" <mardani29@yahoo.es>
Cc: 63495@debbugs.gnu.org, obriendavid1@gmail.com, me@eshelyaron.com
Subject: bug#63495: 28.2; menu crashes on macos
Date: Thu, 13 Jul 2023 20:41:23 +0100	[thread overview]
Message-ID: <ZLBTY5VRcQTmCAaj@idiocy.org> (raw)
In-Reply-To: <m1y1jkfba0.fsf@yahoo.es>

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





  reply	other threads:[~2023-07-13 19:41 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-13 15:36 bug#63495: 28.2; menu crashes on macos David O'Brien
2023-05-14  9:18 ` Eli Zaretskii
2023-07-08 18:18 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-09  7:29   ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-10 21:00     ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-10 22:33       ` Alan Third
2023-07-11  5:40         ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-12 17:25           ` Alan Third
2023-07-12 17:44             ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-12 19:37               ` Alan Third
2023-07-13  6:16                 ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-13  8:47                   ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-13 19:41                     ` Alan Third [this message]
2023-07-25 16:16                     ` Alan Third
2023-07-25 17:47                       ` Eli Zaretskii
2023-09-06 20:16                         ` Stefan Kangas
2023-09-06 20:29                           ` Alan Third
2023-09-06 22:34                             ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-07  5:23                           ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZLBTY5VRcQTmCAaj@idiocy.org \
    --to=alan@idiocy.org \
    --cc=63495@debbugs.gnu.org \
    --cc=mardani29@yahoo.es \
    --cc=me@eshelyaron.com \
    --cc=obriendavid1@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.