Index: /trunk/psphot/src/psphotChoosePSF.c
===================================================================
--- /trunk/psphot/src/psphotChoosePSF.c	(revision 9316)
+++ /trunk/psphot/src/psphotChoosePSF.c	(revision 9317)
@@ -76,11 +76,14 @@
     // select the best of the models
     // here we are using the clippedStdev on the metric as the indicator
-    try = models->data[0];
-    int bestN = 0;
-    float bestM = try->psf->dApResid;
-    for (int i = 1; i < models->n; i++) {
+    int bestN = -1;
+    float bestM = 0.0;
+    for (int i = 0; i < models->n; i++) {
         try = models->data[i];
+	if (try == NULL) {
+	    psError(PSPHOT_ERR_PSF, false, "PSF model %d is NULL", i);
+	    continue;
+	}
         float M = try->psf->dApResid;
-        if (M < bestM) {
+        if (bestN < 0 || M < bestM) {
             bestM = M;
             bestN = i;
@@ -89,4 +92,10 @@
 
     // use the best model:
+    if (bestN < 0) {
+	psError(PSPHOT_ERR_PSF, false, "Failed to fit any models when choosing PSF");
+	psFree (models);
+	return NULL;
+    }
+    
     try = models->data[bestN];
 
