Subject: bug#58857: 28.2; Emacs on macOS seg faults when deleting fullscreen frame

From: Kevin Lin <[email-masked]>
Date: Fri, 28 Oct 2022 10:59:16 -0700

Using stock Emacs 28.2 from https://emacsformacosx.com/:

1) $ /Applications/Emacs.app/Contents/MacOS/Emacs -Q

2) open a second frame by, e.g., C-X-5-2

3) make it fullscreen, e.g., by clicking the green title button

4) delete the fullscreened frame by, e.g., C-X-5-0

I don't know enough about ObjC or NS to isolate the issue in the ObjC source, but the following work-around works for me:

(defun frame-turn-off-fullscreen (theframe)
  (if (eq 'fullboth
	  (cdr (assq 'fullscreen
		     (frame-parameters theframe))))
      (set-frame-parameter theframe 'fullscreen nil)))

(if (boundp 'ns-use-native-fullscreen)
    (add-to-list 'delete-frame-functions 'frame-turn-off-fullscreen))

I haven't tried this with Emacs in gdb, but do have macOS-generated crash logs I can send along upon request.

Also, I'm running this on macOS 13 (Ventura), but this has happened to me since macOS 10.13 (High Sierra) with Emacs 27 (possibly even earlier).  Reporting it only now because the work-around above has worked for me and I forgot about it.

In GNU Emacs 28.2 (build 1, x86_64-apple-darwin18.7.0, NS appkit-1671.60 Version 10.14.6 (Build 18G95))
of 2022-09-12 built on builder10-14.lan
Windowing system distributor 'Apple', version 10.3.2299
System Description:  macOS 13.0

Configured using:
'configure --with-ns '--enable-locallisppath=/Library/Application
Support/Emacs/${version}/site-lisp:/Library/Application
Support/Emacs/site-lisp' --with-modules'

Configured features:
ACL GMP GNUTLS JSON LIBXML2 MODULES NOTIFY KQUEUE NS PDUMPER THREADS
TOOLKIT_SCROLL_BARS ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
rfc822 mml mml-sec epa derived epg rfc6068 epg-config gnus-util rmail
rmail-loaddefs auth-source cl-seq eieio eieio-core cl-macs
eieio-loaddefs password-cache json map text-property-search time-date
subr-x seq byte-opt gv bytecomp byte-compile cconv mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs
cl-lib sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
iso-transl tooltip eldoc paren electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel term/ns-win ns-win ucs-normalize
mule-util term/common-win tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode lisp-mode prog-mode register
page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice button
loaddefs faces cus-face macroexp files window text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote threads kqueue cocoa ns multi-tty
make-network-process emacs)

Memory information:
((conses 16 51043 7955)
(symbols 48 6562 1)
(strings 32 18364 2902)
(string-bytes 1 612723)
(vectors 16 13832)
(vector-slots 8 191713 10825)
(floats 8 21 39)
(intervals 56 222 0)
(buffers 992 11))
--