# HG changeset patch
# Parent 0c921ec04c5b142030f31823ffc5d823c366cab5

diff --git a/src/sampling/sampledSet/midPoint/midPointSet.C b/src/sampling/sampledSet/midPoint/midPointSet.C
--- a/src/sampling/sampledSet/midPoint/midPointSet.C
+++ b/src/sampling/sampledSet/midPoint/midPointSet.C
@@ -53,7 +53,7 @@
 
     label sampleI = 0;
 
-    while(true)
+    while(true && size()>0)
     {
         // calculate midpoint between sampleI and sampleI+1 (if in same segment)
         while
@@ -98,6 +98,12 @@
         sampleI++;
     }
 
+    if(midI==0) {
+        WarningIn("Foam::midPointSet::genSamples()")
+            << "No sample points for " << name() 
+                <<endl;
+    }
+
     midPoints.setSize(midI);
     midCells.setSize(midI);
     midSegments.setSize(midI);
diff --git a/src/sampling/sampledSet/midPointAndFace/midPointAndFaceSet.C b/src/sampling/sampledSet/midPointAndFace/midPointAndFaceSet.C
--- a/src/sampling/sampledSet/midPointAndFace/midPointAndFaceSet.C
+++ b/src/sampling/sampledSet/midPointAndFace/midPointAndFaceSet.C
@@ -55,7 +55,7 @@
 
     label sampleI = 0;
 
-    while(true)
+    while(true && size()>0)
     {
         // sampleI is start of segment
 
@@ -122,6 +122,12 @@
         sampleI++;
     }
 
+    if(newSampleI==0) {
+        WarningIn("Foam::midPointAndFaceSet::genSamples()")
+            << "No sample points for " << name() 
+                <<endl;
+    }
+
     newSamplePoints.setSize(newSampleI);
     newSampleCells.setSize(newSampleI);
     newSampleFaces.setSize(newSampleI);
