Index: trunk/psModules/src/objects/pmSourceMatch.c
===================================================================
--- trunk/psModules/src/objects/pmSourceMatch.c	(revision 26076)
+++ trunk/psModules/src/objects/pmSourceMatch.c	(revision 27162)
@@ -8,4 +8,5 @@
 
 #include "pmSource.h"
+#include "pmErrorCodes.h"
 
 #include "pmSourceMatch.h"
@@ -608,10 +609,40 @@
     int numImages = zp->n;              // Number of images
     int numStars = matches->n;          // Number of stars
+    psVector *badImage = psVectorAlloc(numImages, PS_TYPE_U8); // Bad image?
+    psVectorInit(badImage, 0);
+
+    // Check for data integrity
+    {
+        psVector *num = psVectorAlloc(numImages, PS_TYPE_S32); // Number of stars per image
+        for (int i = 0; i < numStars; i++) {
+            pmSourceMatch *match = matches->data[i]; // Matched stars
+            for (int j = 0; j < match->num; j++) {
+                if (match->mask->data.PS_TYPE_VECTOR_MASK_DATA[j] & PM_SOURCE_MATCH_MASK_PHOT) {
+                    continue;
+                }
+                int index = match->image->data.U32[j]; // Image index
+                num->data.S32[index]++;
+            }
+        }
+        int numGood = 0;                // Number of good images
+        for (int i = 0; i < numImages; i++) {
+            if (num->data.S32[i] == 0 || !isfinite(zp->data.F32[i])) {
+                badImage->data.U8[i] = 0xFF;
+                continue;
+            }
+            numGood++;
+        }
+        psFree(num);
+        if (numGood == 0) {
+            psError(PM_ERR_DATA, true, "No images with good stars.");
+            psFree(badImage);
+            return false;
+        }
+    }
+
     psVector *trans = psVectorAlloc(numImages, PS_TYPE_F32); // Transparencies for each image, magnitudes
     psVectorInit(trans, 0.0);
     psVector *photo = psVectorAlloc(numImages, PS_TYPE_U8); // Photometric determination for each image
     psVectorInit(photo, 0);
-    psVector *badImage = psVectorAlloc(numImages, PS_TYPE_U8); // Bad image?
-    psVectorInit(badImage, 0);
     psVector *stars = psVectorAlloc(numStars, PS_TYPE_F32); // Magnitudes for each star
 
