Subject: Re: bug#59794: 29.0.60; NSport segfaults when a fullscreen frame is being closed)

From: Eli Zaretskii <[email-masked]>
Date: Sun, 04 Dec 2022 12:24:15 +0200

> From: Po Lu <[email-masked]>
> Cc: Kai Ma <[email-masked]>,  Gerd Möllmann
>  <[email-masked]>,
>   [email-masked]
> Date: Sun, 04 Dec 2022 17:10:05 +0800
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> >> From: Kai Ma <[email-masked]>
> >> Date: Sat, 03 Dec 2022 18:48:15 +0800
> >> 
> >> I'm currently using the trivial fix to prevent further data loss:
> >
> > Maybe we should install this fix.  Does anyone see a problem with it?
> 
> Could you please forward the patch in that message?

Why, cannot you access debbugs?

Anyway, attached below.

>>From 8ea35a8099f34f482d090ea8068e89f52dcd29ac Mon Sep 17 00:00:00 2001
From: Kai Ma <[email-masked]>
Date: Sat, 3 Dec 2022 18:17:26 +0800
Subject: [PATCH] Prevent a segfault when deleting a fullscreen frame on
 NextStep.

* nsterm.m ([EmacsView resetCursorRects:]): Be defensive when
accessing FRAME_OUTPUT_DATA.
---
 src/nsterm.m | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/nsterm.m b/src/nsterm.m
index 507f2a9e7d..c09f743ec7 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -6703,8 +6703,16 @@ - (BOOL)acceptsFirstResponder
 
 - (void)resetCursorRects
 {
-  NSRect visible = [self visibleRect];
-  NSCursor *currentCursor = FRAME_POINTER_TYPE (emacsframe);
+  NSRect visible;
+  NSCursor *currentCursor;
+
+  /* On macOS 13, [resetCursorRects:] could be called even after the
+     window is closed. */
+  if (! emacsframe || ! FRAME_OUTPUT_DATA (emacsframe))
+    return;
+
+  visible = [self visibleRect];
+  currentCursor = FRAME_POINTER_TYPE (emacsframe);
   NSTRACE ("[EmacsView resetCursorRects]");
 
   if (currentCursor == nil)
-- 
2.37.1 (Apple Git-137.1)