c6103b8638b54e6e2698dc041647464b7294b838
jcasper
  Wed May 16 10:45:03 2018 -0700
Fixing a potential long/endless loop issue, refs #21462

diff --git src/hg/hgTracks/simpleTracks.c src/hg/hgTracks/simpleTracks.c
index 9161212..1d376ae 100644
--- src/hg/hgTracks/simpleTracks.c
+++ src/hg/hgTracks/simpleTracks.c
@@ -3856,30 +3856,36 @@
 
 		else
 		    drawScaledBox(hvg, s, e, scale, xOff, y, heightPer, color);
                 }
 
             /* Display barbs only if no intron is visible on the item.
                This occurs when the exon completely spans the window,
                or when it is the first or last intron in the feature and
                the following/preceding intron isn't visible */
             if (exonArrowsAlways
             || (  exonArrows
                && (sf->start <= winStart || sf->start == lf->start)
                && (sf->end   >= winEnd   || sf->end   == lf->end)))
                 {
                 Color barbColor = hvGfxContrastingColor(hvg, color);
+                // This scaling of bases to an image window occurs in several places.
+                // It should really be broken out into a function.
+                if (s < winStart)
+                    s = winStart;
+                if (e > winEnd)
+                    e = winEnd;
                 x1 = round((double)((int)s-winStart)*scale) + xOff;
                 x2 = round((double)((int)e-winStart)*scale) + xOff;
                 w = x2-x1;
                 clippedBarbs(hvg, x1+1, midY, x2-x1-2, tl.barbHeight, tl.barbSpacing,
                              lf->orientation, barbColor, TRUE);
                 }
             }
 	}
     }
 
 if ((intronGap > 0) || chainLines)
     lfDrawSpecialGaps(lf, intronGap, chainLines, gapFactor,
 		      tg, hvg, xOff, y, scale, color, bColor, vis);
 
 if (vis != tvDense)