Index: /issm/trunk-jpl/src/c/classes/FemModel.cpp
===================================================================
--- /issm/trunk-jpl/src/c/classes/FemModel.cpp	(revision 24483)
+++ /issm/trunk-jpl/src/c/classes/FemModel.cpp	(revision 24484)
@@ -5339,8 +5339,8 @@
 		for(int i=0;i<numberofvertices;i++) hmaxvertices_serial[i]=NAN;
 		/*Fill hmaxvertices*/
+		if(this->amrbamg->thicknesserror_threshold>0)	this->GethmaxVerticesFromEstimators(hmaxvertices_serial,ThicknessErrorEstimatorEnum);
+		if(this->amrbamg->deviatoricerror_threshold>0)	this->GethmaxVerticesFromEstimators(hmaxvertices_serial,DeviatoricStressErrorEstimatorEnum);
 		if(this->amrbamg->groundingline_distance>0)		this->GethmaxVerticesFromZeroLevelSetDistance(hmaxvertices_serial,MaskGroundediceLevelsetEnum);
 		if(this->amrbamg->icefront_distance>0)				this->GethmaxVerticesFromZeroLevelSetDistance(hmaxvertices_serial,MaskIceLevelsetEnum);
-		if(this->amrbamg->thicknesserror_threshold>0)	this->GethmaxVerticesFromEstimators(hmaxvertices_serial,ThicknessErrorEstimatorEnum);
-		if(this->amrbamg->deviatoricerror_threshold>0)	this->GethmaxVerticesFromEstimators(hmaxvertices_serial,DeviatoricStressErrorEstimatorEnum);
 	}
 
@@ -5522,4 +5522,5 @@
 	int vid,v1,v2,v3;
 	bool refine;
+	
 
 	/*Fill variables*/
@@ -5543,4 +5544,11 @@
 	if(!error_elements) _error_("error_elements is NULL!\n");
 	if(groupthreshold<DBL_EPSILON) _error_("group threshold is too small!");
+	
+	/*Get mesh*/
+	this->GetMesh(&index,&x,&y,&numberofvertices,&numberofelements);
+	if(numberofelements<0) _error_("number of elements is negative!\n");
+	if(numberofvertices<0) _error_("number of vertices is negative!\n");
+	maxlength		= xNew<IssmDouble>(numberofelements);
+	error_vertices	= xNewZeroInit<IssmDouble>(numberofvertices);
 
 	/*Find the max of the estimators if it was not provided*/
@@ -5552,9 +5560,4 @@
    	}
 	}
-
-	/*Get mesh*/
-	this->GetMesh(&index,&x,&y,&numberofvertices,&numberofelements);
-	maxlength		= xNew<IssmDouble>(numberofelements);
-	error_vertices	= xNewZeroInit<IssmDouble>(numberofvertices);
 
 	/*Fill error_vertices (this is the sum of all elements connected to the vertex)*/
