From 39d3437df95b4fedbafa8f09d64f9c482feed551 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Mon, 2 Aug 2021 23:07:41 +0200 Subject: [PATCH] Fix crash when closing a tab using the close button Looking at the crash backtraces from the bug reports, it seems this is what happens, when you have two tabs open, then click the close button on the non-current tab: - QTabBar::currentChanged() is emitted, the TerminalDisplay pointer is still not null at this point (the code checks for that) - TabbedViewContainer::currentTabChanged() - TabbedViewContainer::activeViewChanged() - ViewManager::activateView(), at this point the TerminalDisplay pointer could be null, which then crashes when we call Widget::setFocus() BUG: 411962 FIXED-IN: 21.12 --- src/ViewManager.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp index 856245cff..3fa109246 100644 --- a/src/ViewManager.cpp +++ b/src/ViewManager.cpp @@ -556,12 +556,12 @@ void ViewManager::focusAnotherTerminal(ViewSplitter *toplevelSplitter) void ViewManager::activateView(TerminalDisplay *view) { - Q_ASSERT(view != nullptr); - - // focus the activated view, this will cause the SessionController - // to notify the world that the view has been focused and the appropriate UI - // actions will be plugged in. - view->setFocus(Qt::OtherFocusReason); + if (view) { + // focus the activated view, this will cause the SessionController + // to notify the world that the view has been focused and the appropriate UI + // actions will be plugged in. + view->setFocus(Qt::OtherFocusReason); + } } void ViewManager::splitLeftRight()