From be195ce70e2c165ddaf7fbb9a57f31cd3d1e206a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Mon, 5 Nov 2018 11:17:26 +0100 Subject: [PATCH] [apps/graph] Fix storage pointers that expired --- apps/graph/values/storage_values_controller.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/graph/values/storage_values_controller.cpp b/apps/graph/values/storage_values_controller.cpp index fe8bcd302..58ffdf9e1 100644 --- a/apps/graph/values/storage_values_controller.cpp +++ b/apps/graph/values/storage_values_controller.cpp @@ -41,10 +41,13 @@ void StorageValuesController::willDisplayCellAtLocation(HighlightCell * cell, in // The cell is a function title cell: if (j == 0 && i > 0) { Shared::BufferFunctionTitleCell * myFunctionCell = (Shared::BufferFunctionTitleCell *)cell; - Shared::ExpiringPointer function = functionStore()->modelForRecord(recordAtColumn(i)); const size_t bufferNameSize = Shared::StorageFunction::k_maxNameWithArgumentSize + 1; char bufferName[bufferNameSize]; - if (isDerivativeColumn(i)) { + bool isDerivative = isDerivativeColumn(i); + /* isDerivativeColumn uses expiring pointers, so "function" must be created + * after the isDerivativeColumn call, else it will expire. */ + Shared::ExpiringPointer function = functionStore()->modelForRecord(recordAtColumn(i)); + if (isDerivative) { function->derivativeNameWithArgument(bufferName, bufferNameSize, StorageCartesianFunctionStore::Symbol()); } else { function->nameWithArgument(bufferName, bufferNameSize, StorageCartesianFunctionStore::Symbol()); @@ -139,9 +142,12 @@ StorageFunctionParameterController * StorageValuesController::functionParameterC } double StorageValuesController::evaluationOfAbscissaAtColumn(double abscissa, int columnIndex) { - Shared::ExpiringPointer function = functionStore()->modelForRecord(recordAtColumn(columnIndex)); TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); - if (isDerivativeColumn(columnIndex)) { + bool isDerivative = isDerivativeColumn(columnIndex); + /* isDerivativeColumn uses expiring pointers, so "function" must be created + * after the isDerivativeColumn call, else it will expire. */ + Shared::ExpiringPointer function = functionStore()->modelForRecord(recordAtColumn(columnIndex)); + if (isDerivative) { return function->approximateDerivative(abscissa, myApp->localContext()); } return function->evaluateAtAbscissa(abscissa, myApp->localContext());