From 64f8c067354e3e23a3a0d4dcdc9de8345bc2fd36 Mon Sep 17 00:00:00 2001 From: stippi Date: Fri, 26 Feb 2010 08:53:10 +0000 Subject: [PATCH] Fix crash on program exit. Always good to use defensive programming techniques... git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@225 94f232f2-1747-11df-bad5-a5bfde151594 --- src/apps/webpositive/LauncherWindow.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/apps/webpositive/LauncherWindow.cpp b/src/apps/webpositive/LauncherWindow.cpp index 4f0dcc143a..4a014a62ef 100644 --- a/src/apps/webpositive/LauncherWindow.cpp +++ b/src/apps/webpositive/LauncherWindow.cpp @@ -353,13 +353,22 @@ void LauncherWindow::MessageReceived(BMessage* message) } case TAB_CHANGED: { - int32 index = message->FindInt32("index"); - SetCurrentWebView(dynamic_cast(m_tabView->ViewForTab(index))); - updateTitle(m_tabView->TabAt(index)->Label()); - m_url->SetText(CurrentWebView()->MainFrameURL()); - // Trigger update of the interface to the new page, by requesting - // to resend all notifications. - CurrentWebView()->WebPage()->ResendNotifications(); + // This message may be received also when the last tab closed, i.e. with index == -1. + int32 index = -1; + message->FindInt32("index", &index); + BWebView* webView = dynamic_cast(m_tabView->ViewForTab(index)); + SetCurrentWebView(webView); + BTab* tab = m_tabView->TabAt(index); + if (tab) + updateTitle(tab->Label()); + else + updateTitle(""); + if (webView) { + m_url->SetText(webView->MainFrameURL()); + // Trigger update of the interface to the new page, by requesting + // to resend all notifications. + webView->WebPage()->ResendNotifications(); + } break; }