From 7f6f9ddb94e6f1437ff19a4781d841c063cc04c5 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 18 Jun 2008 04:12:46 +0000 Subject: [PATCH] * Forgot to clear the lines of the alternate screen buffer on initialization. This would lead to crashes when resizing. * Shuffled code in ResizeTo() a bit to make it more robust in case of error (out of memory). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26004 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/terminal/TerminalBuffer.cpp | 29 +++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/apps/terminal/TerminalBuffer.cpp b/src/apps/terminal/TerminalBuffer.cpp index 21b899791b..7a074bf04e 100644 --- a/src/apps/terminal/TerminalBuffer.cpp +++ b/src/apps/terminal/TerminalBuffer.cpp @@ -45,6 +45,9 @@ TerminalBuffer::Init(int32 width, int32 height, int32 historySize) if (fAlternateScreen == NULL) return B_NO_MEMORY; + for (int32 i = 0; i < height; i++) + fAlternateScreen[i]->Clear(); + return BasicTerminalBuffer::Init(width, height, historySize); } @@ -141,31 +144,31 @@ TerminalBuffer::ResizeTo(int32 width, int32 height, int32 historyCapacity) return error; } - TermPos cursor = fCursor; - // Switch to the alternate screen buffer and resize it. if (fAlternateScreen != NULL) { - _SwitchScreenBuffer(); - + TermPos cursor = fCursor; + fCursor.SetTo(0, 0); fWidth = oldWidth; fHeight = oldHeight; - fCursor.SetTo(0, 0); + + _SwitchScreenBuffer(); error = BasicTerminalBuffer::ResizeTo(width, height, 0); + + fWidth = width; + fHeight = height; + fCursor = cursor; + + // Switch back. + if (!alternateScreenActive) + _SwitchScreenBuffer(); + if (error != B_OK) { // This sucks -- we can't do anything about it. Delete the // alternate screen buffer. _FreeLines(fAlternateScreen, oldHeight); fAlternateScreen = NULL; } - - // Switch back. - if (!alternateScreenActive) - _SwitchScreenBuffer(); - - fWidth = width; - fHeight = height; - fCursor = cursor; } return error;