From fd63f70f6d07e128024d185a7ec0574955b728f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Mon, 6 Jan 2020 13:34:05 +0100 Subject: [PATCH] [apps/variable_box_controller] Fix memoization There was a broken assertion: Create at least 7 functions Go to the calculation app Open the variable box and delete the last function --- apps/variable_box_controller.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/variable_box_controller.cpp b/apps/variable_box_controller.cpp index 8f22dd225..ea54020a7 100644 --- a/apps/variable_box_controller.cpp +++ b/apps/variable_box_controller.cpp @@ -13,6 +13,7 @@ using namespace Shared; using namespace Ion; static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } +static inline KDCoordinate maxInt(int x, int y) { return x > y ? x : y; } VariableBoxController::VariableBoxController() : NestedMenuController(nullptr, I18n::Message::Variables), @@ -268,9 +269,12 @@ void VariableBoxController::resetMemoization() { void VariableBoxController::destroyRecordAtRowIndex(int rowIndex) { // Destroy the record recordAtIndex(rowIndex).destroy(); - // Shift the memoization - assert(rowIndex >= m_firstMemoizedLayoutIndex && rowIndex < m_firstMemoizedLayoutIndex + k_maxNumberOfDisplayedRows); - for (int i = rowIndex - m_firstMemoizedLayoutIndex; i < k_maxNumberOfDisplayedRows - 1; i++) { + // Shift the memoization if needed + if (rowIndex >= m_firstMemoizedLayoutIndex + k_maxNumberOfDisplayedRows) { + // The deleted row is after the memoization + return; + } + for (int i = maxInt(0, rowIndex - m_firstMemoizedLayoutIndex); i < k_maxNumberOfDisplayedRows - 1; i++) { m_layouts[i] = m_layouts[i+1]; } m_layouts[k_maxNumberOfDisplayedRows - 1] = Layout();