Subject: bug#66416: 29.1; Crashes when visiting HELLO file with pgtk on Wayland

From: Eli Zaretskii <[email-masked]>
Date: Mon, 09 Oct 2023 14:24:54 +0300

> From: Yuchen Guo <[email-masked]>
> Date: Sun, 08 Oct 2023 20:32:00 +0000
> 
> 
> Emacs occasionally crashes when displaying multi-lingual text.  It has
> crashed several times in the last few days, such as visiting HELLO file
> or browsing a web page with eww.  Sometime it crashes immediately when
> the HELLO file is visited,  other times it crashes when I scroll the
> screen.
> 
> Worth mentioning is that, to deal with font fallback, I have configured
> a custom fontset:
>   https://codeberg.org/m0p/dotfiles/raw/commit/62d1a6008c0e391a33239a809aee92e4c03f14b5/imports/not-nix-config-files/emacs-init.el

Regardless of our attempts to understand the immediate reason(s) for
these crashes and try preventing them, your setup, viz.:

  (create-fontset-from-fontset-spec
   ;; derived from standard-fontset-spec
   "-*-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-custom")
  (setq my-font-list
	'("NewComputerModernMono10"
	  "STIX Two Math"
	  "Noto Sans Mono CJK SC"))
  (dolist (font my-font-list)
    (set-fontset-font "fontset-custom" 'unicode (font-spec :name font) nil 'append))
  (add-to-list 'default-frame-alist
	       '(font . "fontset-custom"))

is not a good idea, to say the least.  Since 'unicode' is a script
that includes all the characters supported by Emacs, the above
basically tells Emacs that each of the 3 fonts you name support the
entire Unicode range of characters, and that cannot be right.

The correct way of customizing your fonts is set a single
ASCII-compatible font as the default font (in your case, this is
probably NewComputerModernMono10), and then use set-fontset-font to
add the other two fonts for specific scripts or ranges of character
codepoints, not for the entire Unicode space.  For each such font use
only the range of characters that it supports well, and that other
fonts don't cover or cover less well.