1. Zero out the residuals vector before it is used. 2. explicit comparison with NULL for jacobian and residuals pointers.
diff --git a/internal/ceres/program_evaluator.h b/internal/ceres/program_evaluator.h index 7ec74b1..b309aad 100644 --- a/internal/ceres/program_evaluator.h +++ b/internal/ceres/program_evaluator.h
@@ -126,7 +126,11 @@ return false; } - if (jacobian) { + if (residuals != NULL) { + VectorRef(residuals, program_->NumResiduals()).setZero(); + } + + if (jacobian != NULL) { jacobian->SetZero(); }