Index: trunk/psModules/src/objects/pmFootprintAssignPeaks.c
===================================================================
--- trunk/psModules/src/objects/pmFootprintAssignPeaks.c	(revision 30621)
+++ trunk/psModules/src/objects/pmFootprintAssignPeaks.c	(revision 31153)
@@ -46,10 +46,10 @@
      */
     psImage *ids = pmSetFootprintArrayIDs(footprints, true);
-    assert (ids != NULL);
-    assert (ids->type.type == PS_TYPE_S32);
-    const int row0 = ids->row0;
-    const int col0 = ids->col0;
-    const int numRows = ids->numRows;
-    const int numCols = ids->numCols;
+    if (ids) { assert (ids->type.type == PS_TYPE_S32); }
+    
+    const int row0 = ids ? ids->row0 : 0;
+    const int col0 = ids ? ids->col0 : 0;
+    const int numRows = ids ? ids->numRows : -1;
+    const int numCols = ids ? ids->numCols : -1;
 
     for (int i = 0; i < peaks->n; i++) {
@@ -58,6 +58,7 @@
 	const int y = peak->y - row0;
 	
-	assert (x >= 0 && x < numCols && y >= 0 && y < numRows);
-	int id = ids->data.S32[y][x - col0];
+	if (ids) { assert (x >= 0 && x < numCols && y >= 0 && y < numRows);}
+	int id = ids ? ids->data.S32[y][x - col0] : 0;
+	// XXX I think the '[x - col0]' above is just wrong (should be [x], but never gets triggerd.
 
 	if (id == 0) {			// peak isn't in a footprint, so make one for it
@@ -86,5 +87,10 @@
 	if (fp->peaks->n == 1) continue;
 
-        fp->peaks = psArraySort(fp->peaks, pmPeakSortBySN);
+	// make sure the peaks are sorted in a way consistent with our cull process
+	if (PM_PEAKS_CULL_WITH_SMOOTHED_IMAGE) {
+	    fp->peaks = psArraySort(fp->peaks, pmPeaksSortBySmoothFluxDescend);
+	} else {
+	    fp->peaks = psArraySort(fp->peaks, pmPeaksSortByRawFluxDescend);
+	}
 
 	// XXX check for an assert on duplicates (I don't think they can happen, but
