Subject: bug#63312: 29.0.90; set-frame-parameter sometimes called with dead frame when quitting ediff

From: Eli Zaretskii <[email-masked]>
Date: Sat, 06 May 2023 12:42:02 +0300

> Date: Fri, 5 May 2023 19:02:10 +0200
> From: Tobias Bading <[email-masked]>
> 
> 1. emacs -Q
> 
> 2. Open a file under version control, e.g. lisp/vc/ediff-util.el
> 
> 3. Selecting some text with the mouse seems to increase the chance of the
>    error occurring, maybe even select some text in another application
> 
> 4. M-x ediff-revision RET RET RET RET
> 
> 5. q RET
> 
> Sometimes this results in error
> 
> set-frame-parameter: Wrong type argument: frame-live-p, #<dead frame Ediff 0x560ee1b46200>
> 
> With
> 
> (trace-function-background 'set-frame-parameter)
> (trace-function-background 'x-dnd-after-move-frame)
> (trace-function-background 'handle-move-frame)
> 
> prior to quitting ediff, the error is logged as
> 
> 1 -> (handle-move-frame (move-frame (#<dead frame Ediff 0x5643a7425888>)))
> | 2 -> (x-dnd-after-move-frame #<dead frame Ediff 0x5643a7425888>)
> | | 3 -> (set-frame-parameter #<dead frame Ediff 0x5643a7425888> dnd-root-window-position nil)
> | | 3 <- set-frame-parameter: !non-local\ exit!
> | 2 <- x-dnd-after-move-frame: !non-local\ exit!
> 1 <- handle-move-frame: !non-local\ exit!

Does the patch below give good results?

diff --git a/lisp/x-dnd.el b/lisp/x-dnd.el
index 9286a18..acfbbed 100644
--- a/lisp/x-dnd.el
+++ b/lisp/x-dnd.el
@@ -609,8 +609,9 @@ x-dnd-init-xdnd-for-frame
 (defun x-dnd-after-move-frame (frame)
   "Handle FRAME moving to a different position.
 Clear any cached root window position."
-  (set-frame-parameter frame 'dnd-root-window-position
-                       nil))
+  (and (frame-live-p frame)
+       (set-frame-parameter frame 'dnd-root-window-position
+                            nil)))
 
 (add-hook 'move-frame-functions #'x-dnd-after-move-frame)