Skip to content

Commit

Permalink
Protect the command palette against being paged with no items (#12528)
Browse files Browse the repository at this point in the history
Fixes two crashes amounting to 14% of our crash burden in Simulated
Selfhost. I can't reproduce this organically, but I was able to do so by
forcing the command palette to be empty.
  • Loading branch information
DHowett authored Feb 22, 2022
1 parent 4016a9f commit 30aa514
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/cascadia/TerminalApp/CommandPalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,16 @@ namespace winrt::TerminalApp::implementation
// - the approximate number of items visible in the list (in other words the size of the page)
uint32_t CommandPalette::_getNumVisibleItems()
{
const auto container = _filteredActionsView().ContainerFromIndex(0);
const auto item = container.try_as<winrt::Windows::UI::Xaml::Controls::ListViewItem>();
const auto itemHeight = ::base::saturated_cast<int>(item.ActualHeight());
const auto listHeight = ::base::saturated_cast<int>(_filteredActionsView().ActualHeight());
return listHeight / itemHeight;
if (const auto container = _filteredActionsView().ContainerFromIndex(0))
{
if (const auto item = container.try_as<winrt::Windows::UI::Xaml::Controls::ListViewItem>())
{
const auto itemHeight = ::base::saturated_cast<int>(item.ActualHeight());
const auto listHeight = ::base::saturated_cast<int>(_filteredActionsView().ActualHeight());
return listHeight / itemHeight;
}
}
return 0;
}

// Method Description:
Expand Down

0 comments on commit 30aa514

Please sign in to comment.