#51 wip
[fanfix.git] / src / jexer / TTerminalWidget.java
index 7a93f4e7b32320c69ade2090049146e9200fdef0..39d761c64a1b2ae06fe2df6a5cbd1a143a8b4b5e 100644 (file)
@@ -384,6 +384,14 @@ public class TTerminalWidget extends TScrollableWidget
                 // Update the scroll bars
                 reflowData();
 
+                if (!isDrawable()) {
+                    // We lost the connection, onShellExit() called an action
+                    // that ultimately removed this widget from the UI
+                    // hierarchy, so no one cares if we update the display.
+                    // Bail out.
+                    return;
+                }
+
                 if ((scrollback == null) || emulator.isReading()) {
                     scrollback = copyBuffer(emulator.getScrollbackBuffer());
                     display = copyBuffer(emulator.getDisplayBuffer());
@@ -820,17 +828,19 @@ public class TTerminalWidget extends TScrollableWidget
     public void onShellExit() {
         TApplication app = getApplication();
         if (app != null) {
-            app.invokeLater(new Runnable() {
-                public void run() {
-                    if (closeAction != null) {
+            if (closeAction != null) {
+                // We have to put this action inside invokeLater() because it
+                // could be executed during draw() when syncing with ECMA48.
+                app.invokeLater(new Runnable() {
+                    public void run() {
                         closeAction.DO(TTerminalWidget.this);
                     }
-                    if (getApplication() != null) {
-                        getApplication().postEvent(new TMenuEvent(
-                            TMenu.MID_REPAINT));
-                    }
-                }
-            });
+                });
+            }
+            if (getApplication() != null) {
+                getApplication().postEvent(new TMenuEvent(
+                    TMenu.MID_REPAINT));
+            }
         }
     }