From 3e4a67bee14cefbcc119c7be6dd0fe0040814fb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 31 Jul 2018 17:09:42 +0200 Subject: [PATCH] [poincare] Check if layout is not AllocFail when adding row after column --- poincare/src/matrix_layout_node.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/poincare/src/matrix_layout_node.cpp b/poincare/src/matrix_layout_node.cpp index c7f956cc6..83aba4859 100644 --- a/poincare/src/matrix_layout_node.cpp +++ b/poincare/src/matrix_layout_node.cpp @@ -161,9 +161,10 @@ void MatrixLayoutNode::moveCursorVertically(VerticalDirection direction, LayoutC void MatrixLayoutNode::newRowOrColumnAtIndex(int index) { assert(index >= 0 && index < m_numberOfColumns*m_numberOfRows); + LayoutRef rootRef = LayoutRef(root()); bool shouldAddNewRow = childIsBottomOfGrid(index); // We need to compute this boolean before modifying the layout int correspondingRow = rowAtChildIndex(index); - if (childIsRightOfGrid(index)) { + if (childIsRightOfGrid(index)) { // Color the grey EmptyLayouts of the column in yellow. int correspondingColumn = m_numberOfColumns - 1; for (int i = 0; i < m_numberOfRows - 1; i++) { @@ -175,6 +176,9 @@ void MatrixLayoutNode::newRowOrColumnAtIndex(int index) { // Add a column of grey EmptyLayouts on the right. addEmptyColumn(EmptyLayoutNode::Color::Grey); } + if (rootRef.isAllocationFailure()) { + return; + } if (shouldAddNewRow) { // Color the grey EmptyLayouts of the row in yellow. for (int i = 0; i < m_numberOfColumns - 1; i++) {