From 49df52abc004419f35bb6b508fb681c028a7c679 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 2 Feb 2011 13:20:11 +1000 Subject: Avoid index-out-of bounds related crash in Grid Task-number: QTBUG-16959 Reviewed-by: Martin Jones --- .../graphicsitems/qdeclarativepositioners.cpp | 2 +- .../qdeclarativepositioners/data/repeatertest.qml | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp index 9450647..4560d32 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp +++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp @@ -939,7 +939,7 @@ void QDeclarativeGrid::doPositioning(QSizeF *contentSize) if (i==0) maxColWidth << 0; - if (childIndex == positionedItems.count()) + if (childIndex == visibleItems.count()) break; const PositionedItem &child = visibleItems.at(childIndex++); diff --git a/tests/auto/declarative/qdeclarativepositioners/data/repeatertest.qml b/tests/auto/declarative/qdeclarativepositioners/data/repeatertest.qml index 1cba598..f93ce67 100644 --- a/tests/auto/declarative/qdeclarativepositioners/data/repeatertest.qml +++ b/tests/auto/declarative/qdeclarativepositioners/data/repeatertest.qml @@ -12,9 +12,27 @@ Item { height: 50 z: {if(index == 0){2;}else if(index == 1){1;} else{3;}} objectName: {if(index == 0){"one";}else if(index == 1){"two";} else{"three";}} - } } } } + + //This crashed once (QTBUG-16959) because the repeater ended up on the end of the list + //If this grid just instantiates without crashing, then it has not regressed. + Grid { + id: grid + rows: 2 + flow: Grid.TopToBottom + + Repeater { + model: 13 + Rectangle { + color: "goldenrod" + width: 100 + height: 100 + radius: 10 + border.width: 1 + } + } + } } -- cgit v0.12