Don't crash on die() if window is already dead
authorJack Miller <jack@codezen.org>
Fri, 17 Oct 2014 18:31:01 +0000 (13:31 -0500)
committerJack Miller <jack@codezen.org>
Fri, 17 Oct 2014 18:31:01 +0000 (13:31 -0500)
Resizes and other mundane stuff can cause a window to be killed and
refreshed, so if a die() is called from a command and the window isn't
being tracked by the Screen, just forget about it.

canto_curses/screen.py

index e25f8af..fb7098d 100644 (file)
@@ -517,23 +517,28 @@ class Screen(CommandHandler):
     def die_callback(self, window):
         sync_lock.acquire_write()
 
-        # Call the window's die function
-        window.die()
-
         # Remove window from both window_types and the general window list
-        idx = self.windows.index(window)
-        del self.windows[idx]
-        del self.window_types[idx]
 
-        # Regenerate layout with remaining windows.
-        self.subwindows()
+        try:
+            idx = self.windows.index(window)
+        except:
+            pass
+        else:
+            # Call the window's die function
+            window.die()
 
-        self.refresh()
+            del self.windows[idx]
+            del self.window_types[idx]
 
-        # Force a doupdate because refresh doesn't, but we have possibly
-        # uncovered part of the screen that isn't handled by any other window.
+            # Regenerate layout with remaining windows.
+            self.subwindows()
 
-        curses.doupdate()
+            self.refresh()
+
+            # Force a doupdate because refresh doesn't, but we have possibly
+            # uncovered part of the screen that isn't handled by any other window.
+
+            curses.doupdate()
 
         sync_lock.release_write()