Index: src/hg/hgTracks/imageV2.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/hgTracks/imageV2.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -b -B -U 4 -r1.21 -r1.22
--- src/hg/hgTracks/imageV2.c	9 Feb 2010 00:11:33 -0000	1.21
+++ src/hg/hgTracks/imageV2.c	10 Feb 2010 00:37:56 -0000	1.22
@@ -417,8 +417,10 @@
 struct imgSlice *sliceCreate(enum sliceType type,struct image *img,char *title,int width,int height,int offsetX,int offsetY)
 /* Creates of a slice which is a portion of an image.
    A slice specific map map be added with sliceMapStart(),mapSetItemAdd() */
 {
+if (height <= 0 || width <= 0)
+    return NULL;
 struct imgSlice *slice;
 AllocVar(slice);
 slice->map       = NULL; // This is the same as defaulting to slice->parentImg->map
 return sliceUpdate(slice,type,img,title,width,height,offsetX,offsetY);
@@ -514,8 +516,10 @@
 
 struct mapSet *sliceMapFindOrStart(struct imgSlice *slice,char *name,char *linkRoot)
 /* Finds the slice specific map or starts it */
 {
+if(slice==NULL)
+    return NULL;
 struct mapSet *map = sliceGetMap(slice,TRUE); // Must be specific to this slice
 if (map == NULL)
     map = sliceMapStart(slice,name,linkRoot);
 return map;
@@ -1236,8 +1240,29 @@
         *dy = myDy;
     }
 }
 
+int imgBoxDropEmpties(struct imgBox *imgBox)
+/* Empty imageTracks (without slices) is not an error but they should be dropped.
+   returns remaining current track count */
+{
+if (imgBox == NULL)
+    return 0;
+struct imgTrack *imgTrack = imgBox->imgTracks;
+while(imgTrack != NULL)
+    {
+    if(imgTrack->slices == NULL)
+        {
+        slRemoveEl(&(imgBox->imgTracks),imgTrack);
+        imgTrackFree(&imgTrack);
+        imgTrack = imgBox->imgTracks; // start over
+        continue;
+        }
+    imgTrack = imgTrack->next;
+    }
+return slCount(imgBox->imgTracks);
+}
+
 boolean imgBoxIsComplete(struct imgBox *imgBox,boolean verbose)
 /* Tests the completeness and consistency of an imgBox. */
 {
 if (imgBox == NULL)
@@ -1286,10 +1311,10 @@
     if (verbose)
         warn("imgBox(%s.%s:%d-%d) has no imgTracks",imgBox->db,imgBox->chrom,imgBox->chromStart,imgBox->chromEnd);
     return FALSE;
     }
-struct imgTrack *imgTrack = NULL;
-for (imgTrack = imgBox->imgTracks; imgTrack != NULL; imgTrack = imgTrack->next )
+struct imgTrack *imgTrack = imgBox->imgTracks;
+while(imgTrack != NULL)
     {
     if(!imgTrackIsComplete(imgTrack,verbose))
         {
         if (verbose)
@@ -1311,25 +1336,11 @@
                   imgBox->db,  imgBox->chrom,  imgBox->chromStart,  imgBox->chromEnd,
                 imgTrack->db,imgTrack->chrom,imgTrack->chromStart,imgTrack->chromEnd);
         return FALSE;
     }
-    // Every track must have slices
-    if (imgTrack->slices == NULL)
-        {
-        if (verbose)
-            warn("imgBox(%s.%s:%d-%d) has no slices",
-                imgBox->db,imgBox->chrom,imgBox->chromStart,imgBox->chromEnd);
-        return FALSE;
-        }
     struct imgSlice *slice = NULL;
     for (slice = imgTrack->slices; slice != NULL; slice = slice->next )
         {
-        if(!sliceIsConsistent(slice,verbose))
-            {
-            if (verbose)
-                warn("imgBox(%s.%s:%d-%d) has bad slice",imgBox->db,imgBox->chrom,imgBox->chromStart,imgBox->chromEnd);
-            return FALSE;
-            }
         // Every slice that has an image must point to an image owned by the imgBox
         if(slice->parentImg && (slIxFromElement(imgBox->images,slice->parentImg) == -1))
             {
             if (verbose)
@@ -1338,8 +1349,9 @@
                     sliceTypeToString(slice->type),slice->parentImg->file);
             return FALSE;
             }
         }
+    imgTrack = imgTrack->next;
     }
 return TRUE;
 }
 
@@ -1486,9 +1498,9 @@
     }
 
 imageDraw(imgBox,imgTrack,slice,name,offsetX,slice->offsetY,useMap);
 if(slice->link != NULL)
-    hPrintf("</A>\n");
+    hPrintf("</A>");
 
 if(slice->parentImg)
     hPrintf("</div>");
 }
@@ -1497,10 +1509,11 @@
 /* writes a entire imgBox including all tracksas HTML */
 {
 if(imgBox->imgTracks == NULL)  // Not an error to have an empty image
     return;
+imgBoxDropEmpties(imgBox);
 boolean verbose = (hIsPrivateHost());   // Warnings for hgwdev only
-if(!imgBoxIsComplete(imgBox,verbose))
+if(!imgBoxIsComplete(imgBox,verbose)) // dorps empties as okay
     return;
 char name[256];
 int bgOffset = NO_VALUE;
 

