From 441da20d7ca1d90a73887961205ffdf60b802620 Mon Sep 17 00:00:00 2001 From: Oliver Sutton Date: Fri, 17 Nov 2017 15:07:33 +0000 Subject: [PATCH] Fix EXC_BAD_ACCESS occurring when marking all elements for refinement or coarsening using refine_and_coarsen_fixed_number. --- source/grid/grid_refinement.cc | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/source/grid/grid_refinement.cc b/source/grid/grid_refinement.cc index 338bdf9b6a..683031d9bc 100644 --- a/source/grid/grid_refinement.cc +++ b/source/grid/grid_refinement.cc @@ -306,19 +306,29 @@ GridRefinement::refine_and_coarsen_fixed_number (Triangulation &tr Vector tmp (criteria); if (refine_cells) { - std::nth_element (tmp.begin(), tmp.begin()+refine_cells, - tmp.end(), - std::greater()); - refine (tria, criteria, *(tmp.begin() + refine_cells)); + if (static_cast(refine_cells) == criteria.size()) + refine (tria, criteria, -std::numeric_limits::max()); + else + { + std::nth_element (tmp.begin(), tmp.begin()+refine_cells, + tmp.end(), + std::greater()); + refine (tria, criteria, *(tmp.begin() + refine_cells)); + } } if (coarsen_cells) { - std::nth_element (tmp.begin(), tmp.begin()+tmp.size()-coarsen_cells, - tmp.end(), - std::greater()); - coarsen (tria, criteria, - *(tmp.begin() + tmp.size() - coarsen_cells)); + if (static_cast(coarsen_cells) == criteria.size()) + coarsen (tria, criteria, std::numeric_limits::max()); + else + { + std::nth_element (tmp.begin(), tmp.begin()+tmp.size()-coarsen_cells, + tmp.end(), + std::greater()); + coarsen (tria, criteria, + *(tmp.begin() + tmp.size() - coarsen_cells)); + } } } } -- 2.39.5