From 6bc51f97e499eed33a968a44fc5f357f977bf4b2 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 13 Oct 2021 13:10:11 +0100 Subject: [PATCH] Grid: Avoid crashing in performLayout when the grid contains no items --- modules/juce_gui_basics/layout/juce_Grid.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/juce_gui_basics/layout/juce_Grid.cpp b/modules/juce_gui_basics/layout/juce_Grid.cpp index f27b82b6f8..de0a81f510 100644 --- a/modules/juce_gui_basics/layout/juce_Grid.cpp +++ b/modules/juce_gui_basics/layout/juce_Grid.cpp @@ -833,6 +833,9 @@ struct Grid::AutoPlacement template static PlacementHelpers::LineRange findFullLineRange (const ItemPlacementArray& items, Accessor&& accessor) { + if (items.isEmpty()) + return { 1, 1 }; + const auto combine = [&accessor] (const auto& acc, const auto& item) { const auto newRange = accessor (item); @@ -1052,6 +1055,13 @@ struct GridTests : public UnitTest using Tr = Grid::TrackInfo; using Rect = Rectangle; + beginTest ("Layout calculation of an empty grid is a no-op"); + { + const Rectangle bounds { 100, 200 }; + Grid grid; + grid.performLayout (bounds); + } + { Grid grid;