fix stack overflow
authorKevin Lamonte <kevin.lamonte@gmail.com>
Wed, 23 Aug 2017 01:51:56 +0000 (21:51 -0400)
committerKevin Lamonte <kevin.lamonte@gmail.com>
Wed, 23 Aug 2017 01:51:56 +0000 (21:51 -0400)
src/jexer/TApplication.java

index 4457197caeec733fbea251085b9105e1ec4e9940..b4c53ec3a5ea8899db40c6dbdda283abe85153f7 100644 (file)
@@ -1431,9 +1431,15 @@ public class TApplication implements Runnable {
         if (activeWindow != null) {
             assert (activeWindow.getZ() == 0);
 
-            activeWindow.onUnfocus();
             activeWindow.setActive(false);
             activeWindow.setZ(window.getZ());
+
+            // Unset activeWindow now before unfocus, so that a window
+            // lifecycle change inside onUnfocus() doesn't call
+            // switchWindow() and lead to a stack overflow.
+            TWindow oldActiveWindow = activeWindow;
+            activeWindow = null;
+            oldActiveWindow.onUnfocus();
         }
         activeWindow = window;
         activeWindow.setZ(0);