Fix crash in frame deletion on Android
authorPo Lu <luangruo@yahoo.com>
Mon, 17 Feb 2025 03:33:50 +0000 (11:33 +0800)
committerPo Lu <luangruo@yahoo.com>
Mon, 17 Feb 2025 03:33:50 +0000 (11:33 +0800)
* java/org/gnu/emacs/EmacsWindow.java (destroyHandle):
Invalidate the input focus in the UI thread, as is proper.

java/org/gnu/emacs/EmacsWindow.java

index f935850b22b72a5423fa2c2a63614a7c8c411e29..fec955268358789b02eea241d19062de5cbf161d 100644 (file)
@@ -271,20 +271,26 @@ public final class EmacsWindow extends EmacsHandleObject
          }
       }
 
-    EmacsActivity.invalidateFocus (4);
-
+    /* This is just a sanity test and is not reliable since `children'
+       may be modified between isEmpty and handle destruction.  */
     if (!children.isEmpty ())
       throw new IllegalStateException ("Trying to destroy window with "
                                       + "children!");
 
     /* Remove the view from its parent and make it invisible.  */
     EmacsService.SERVICE.runOnUiThread (new Runnable () {
+       @Override
        public void
        run ()
        {
          ViewManager parent;
          EmacsWindowManager manager;
 
+         /* Invalidate the focus; this should transfer the input focus
+            to the next eligible window as this window is no longer
+            present in parent.children.  */
+         EmacsActivity.invalidateFocus (4);
+
          if (EmacsActivity.focusedWindow == EmacsWindow.this)
            EmacsActivity.focusedWindow = null;