Index: trunk/psModules/src/imcombine/pmPSFEnvelope.c
===================================================================
--- trunk/psModules/src/imcombine/pmPSFEnvelope.c	(revision 25754)
+++ trunk/psModules/src/imcombine/pmPSFEnvelope.c	(revision 26893)
@@ -65,5 +65,6 @@
                      int radius,        // Radius of each PSF
                      const char *modelName,// Name of PSF model to use
-                     int xOrder, int yOrder // Order for PSF variation fit
+                     int xOrder, int yOrder, // Order for PSF variation fit
+                     psImageMaskType maskVal
                      )
 {
@@ -154,12 +155,16 @@
             pmModelClassSetLimits(PM_MODEL_LIMITS_IGNORE);
             pmModel *model = pmModelFromPSFforXY(psf, numCols / 2.0, numRows / 2.0, PEAK_FLUX); // Test model
-            model->modelSetLimits(PM_MODEL_LIMITS_STRICT);
-            for (int j = 0; j < model->params->n && goodPSF; j++) {
-                if (!model->modelLimits(PS_MINIMIZE_PARAM_MIN, j, model->params->data.F32, NULL) ||
-                    !model->modelLimits(PS_MINIMIZE_PARAM_MAX, j, model->params->data.F32, NULL)) {
-                    goodPSF = false;
+            if (!model) {
+                goodPSF = false;
+            } else {
+                model->modelSetLimits(PM_MODEL_LIMITS_STRICT);
+                for (int j = 0; j < model->params->n && goodPSF; j++) {
+                    if (!model->modelLimits(PS_MINIMIZE_PARAM_MIN, j, model->params->data.F32, NULL) ||
+                        !model->modelLimits(PS_MINIMIZE_PARAM_MAX, j, model->params->data.F32, NULL)) {
+                        goodPSF = false;
+                    }
                 }
-            }
-            psFree(model);
+                psFree(model);
+            }
             if (!goodPSF) {
                 psWarning("PSF %d is bad --- not including in envelope calculation.", i);
@@ -360,5 +365,6 @@
 
         // measure the source moments: tophat windowing, no pixel S/N cutoff
-        if (!pmSourceMoments(source, maxRadius, 0.0, 1.0)) {
+        // XXX probably should be passing the maskVal to this function so we can pass it along here...
+        if (!pmSourceMoments(source, maxRadius, 0.0, 1.0, maskVal)) {
             // Can't do anything about it; limp along as best we can
             psErrorClear();
