Index: branches/tap_branches/psphot/src/psphotSourceFits.c
===================================================================
--- branches/tap_branches/psphot/src/psphotSourceFits.c	(revision 25900)
+++ branches/tap_branches/psphot/src/psphotSourceFits.c	(revision 27838)
@@ -219,4 +219,7 @@
     double chiTrend;
     pmModel *ONE = NULL;
+    pmSource *tmpSrc = NULL;
+    pmModel *EXT = NULL;
+    psArray *DBL = NULL;
 
     // skip the source if we don't think it is extended
@@ -232,5 +235,5 @@
     // at this stage, skip Gaussian windowing, and do not clip pixels by S/N
     // this uses the footprint to judge both radius and aperture?
-    if (!pmSourceMoments (source, radius, 0.0, 0.0)) return false;
+    if (!pmSourceMoments (source, radius, 0.0, 0.0, maskVal)) return false;
 
     psTrace ("psphot", 5, "trying blob...\n");
@@ -240,9 +243,10 @@
 
     // this temporary source is used as a place-holder by the psphotEval functions below
-    pmSource *tmpSrc = pmSourceAlloc ();
+    tmpSrc = pmSourceAlloc ();
 
     // XXX need to handle failures better here
-    pmModel *EXT = psphotFitEXT (readout, source, modelTypeEXT, maskVal, markVal);
-    if (!isfinite(EXT->params->data.F32[PM_PAR_I0])) psAbort("nan in fit");
+    EXT = psphotFitEXT (readout, source, modelTypeEXT, maskVal, markVal);
+    if (!EXT) goto escape;
+    if (!isfinite(EXT->params->data.F32[PM_PAR_I0])) goto escape;
 
     okEXT = psphotEvalEXT (tmpSrc, EXT);
@@ -250,5 +254,8 @@
 
     // DBL will always be defined, but DBL->data[n] might not
-    psArray *DBL = psphotFitDBL (readout, source, maskVal, markVal);
+    DBL = psphotFitDBL (readout, source, maskVal, markVal);
+    if (!DBL) goto escape;
+    if (!DBL->n) goto escape;
+
     okDBL  = psphotEvalDBL (tmpSrc, DBL->data[0]);
     okDBL &= psphotEvalDBL (tmpSrc, DBL->data[1]);
@@ -362,4 +369,11 @@
     psFree (DBL);
     return true;
+
+escape:
+    psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 
+    psFree (tmpSrc);
+    psFree (EXT);
+    psFree (DBL);
+    return false;
 }
 
@@ -425,5 +439,8 @@
     // use the source moments, etc to guess basic model parameters
     pmModel *EXT = pmSourceModelGuess (source, modelType);
-    PS_ASSERT (EXT, NULL);
+    if (!EXT) {
+	psTrace ("psphot", 5, "failed to generate a model for source: moments: %f %f\n", source->moments->Mxx, source->moments->Myy);
+	return NULL;
+    }
 
     if ((source->moments->Mxx < 1e-3) || (source->moments->Myy < 1e-3)) {
