diff --git a/apps/calculation/additional_outputs/illustrated_list_controller.cpp b/apps/calculation/additional_outputs/illustrated_list_controller.cpp index b4d895621..1b78bef20 100644 --- a/apps/calculation/additional_outputs/illustrated_list_controller.cpp +++ b/apps/calculation/additional_outputs/illustrated_list_controller.cpp @@ -1,4 +1,5 @@ #include "illustrated_list_controller.h" +#include #include #include "../app.h" @@ -82,6 +83,10 @@ KDCoordinate IllustratedListController::rowHeight(int j) { KDCoordinate result = calculation->memoizedHeight(expanded); if (result < 0) { result = ScrollableThreeExpressionsCell::Height(calculation.pointer()); + if (result < 0) { + // Raise, because Height modified the calculation and failed. + Poincare::ExceptionCheckpoint::Raise(); + } calculation->setMemoizedHeight(expanded, result); } return result + Metric::CellSeparatorThickness; diff --git a/apps/calculation/additional_outputs/scrollable_three_expressions_cell.cpp b/apps/calculation/additional_outputs/scrollable_three_expressions_cell.cpp index 29fe03a9a..63cf7b17e 100644 --- a/apps/calculation/additional_outputs/scrollable_three_expressions_cell.cpp +++ b/apps/calculation/additional_outputs/scrollable_three_expressions_cell.cpp @@ -8,7 +8,8 @@ void ScrollableThreeExpressionsView::resetMemoization() { setLayouts(Poincare::Layout(), Poincare::Layout(), Poincare::Layout()); } -void ScrollableThreeExpressionsView::setCalculation(Calculation * calculation) { +void ScrollableThreeExpressionsView::setCalculation(Calculation * calculation, bool * didForceOutput) { + assert(!didForceOutput || *didForceOutput == false); Poincare::Context * context = App::app()->localContext(); // Clean the layouts to make room in the pool @@ -27,6 +28,9 @@ void ScrollableThreeExpressionsView::setCalculation(Calculation * calculation) { Poincare::ExceptionCheckpoint::Raise(); } else { calculation->forceDisplayOutput(::Calculation::Calculation::DisplayOutput::ApproximateOnly); + if (didForceOutput) { + *didForceOutput = true; + } } } } @@ -46,6 +50,9 @@ void ScrollableThreeExpressionsView::setCalculation(Calculation * calculation) { /* Set the display output to ApproximateOnly, make room in the pool by * erasing the exact layout, and retry to create the approximate layout */ calculation->forceDisplayOutput(::Calculation::Calculation::DisplayOutput::ApproximateOnly); + if (didForceOutput) { + *didForceOutput = true; + } exactOutputLayout = Poincare::Layout(); couldNotCreateApproximateLayout = false; approximateOutputLayout = calculation->createApproximateOutputLayout(context, &couldNotCreateApproximateLayout); @@ -67,7 +74,16 @@ void ScrollableThreeExpressionsView::setCalculation(Calculation * calculation) { KDCoordinate ScrollableThreeExpressionsCell::Height(Calculation * calculation) { ScrollableThreeExpressionsCell cell; - cell.setCalculation(calculation); + bool didForceOutput = false; + cell.setCalculation(calculation, &didForceOutput); + if (didForceOutput) { + /* We could not compute the height of the calculation as it is (the display + * output was forced to another value during the height computation). + * Warning: the display output of calculation was actually changed, so it + * will cause problems if we already did some computations with another + * display value. */ + return -1; + } KDRect leftFrame = KDRectZero; KDRect centerFrame = KDRectZero; KDRect approximateSignFrame = KDRectZero; @@ -87,8 +103,8 @@ void ScrollableThreeExpressionsCell::reinitSelection() { m_view.reloadScroll(); } -void ScrollableThreeExpressionsCell::setCalculation(Calculation * calculation) { - m_view.setCalculation(calculation); +void ScrollableThreeExpressionsCell::setCalculation(Calculation * calculation, bool * didForceOutput) { + m_view.setCalculation(calculation, didForceOutput); layoutSubviews(); } diff --git a/apps/calculation/additional_outputs/scrollable_three_expressions_cell.h b/apps/calculation/additional_outputs/scrollable_three_expressions_cell.h index e8daa7f26..6dd8f52f3 100644 --- a/apps/calculation/additional_outputs/scrollable_three_expressions_cell.h +++ b/apps/calculation/additional_outputs/scrollable_three_expressions_cell.h @@ -16,7 +16,7 @@ public: setBackgroundColor(KDColorWhite); } void resetMemoization(); - void setCalculation(Calculation * calculation); + void setCalculation(Calculation * calculation, bool * didForceOutput = nullptr); void subviewFrames(KDRect * leftFrame, KDRect * centerFrame, KDRect * approximateSignFrame, KDRect * rightFrame) { return m_contentCell.subviewFrames(leftFrame, centerFrame, approximateSignFrame, rightFrame); } @@ -57,7 +57,7 @@ public: void setHighlighted(bool highlight) override { m_view.evenOddCell()->setHighlighted(highlight); } void resetMemoization() { m_view.resetMemoization(); } - void setCalculation(Calculation * calculation); + void setCalculation(Calculation * calculation, bool * didForceOutput = nullptr); void setDisplayCenter(bool display); ScrollableThreeExpressionsView::SubviewPosition selectedSubviewPosition() { return m_view.selectedSubviewPosition(); } void setSelectedSubviewPosition(ScrollableThreeExpressionsView::SubviewPosition subviewPosition) { m_view.setSelectedSubviewPosition(subviewPosition); }