Index: /trunk/psphot/src/psphotImageMedian.c
===================================================================
--- /trunk/psphot/src/psphotImageMedian.c	(revision 13865)
+++ /trunk/psphot/src/psphotImageMedian.c	(revision 13866)
@@ -255,5 +255,13 @@
         }
     }
-    assert (Count > 0);
+    if (Count == 0) {
+        psError (PSPHOT_ERR_DATA, true, "failed to build background image");
+	psFree(stats);
+	psFree(statsDefaults);
+	psFree(binning);
+	psFree(rng);
+        return false;
+    }
+
     Value /= Count;
     ValueStdev /= Count;
@@ -321,5 +329,5 @@
     // linear interpolation to full-scale
     if (!psImageUnbin (background->image, model->image, binning)) {
-        psError (PSPHOT_ERR_PROG, true, "failed to build background image");
+        psError (PSPHOT_ERR_PROG, true, "inconsistent sizes for unbinning");
         return false;
     }
