5cc24badc6445a420e1b885378cf5ec8d0632189 angie Wed Jul 6 10:51:40 2011 -0700 Bug #4263 (track items not being drawn in hgTracks when zoomed way in):Building on Fan's fix for integer overflow in bedPlusLabelDrawAt's x1 calculation, I changed the x1 and x2 calculations to use pre-clipped chromosome coordinates so that they're using reasonably small inputs. The ISCA Retrospective track (bedDrawSimpleAt) had the same problem with long items and large scale factor causing integer overflow, so I applied the same fix there. hgTracks code still has ~50 places that use the same round((double)(... method, but it takes extreme conditions to cause integer overflow so I'll leave those alone for now. diff --git src/hg/hgTracks/simpleTracks.c src/hg/hgTracks/simpleTracks.c index 925b161..1dc9199 100644 --- src/hg/hgTracks/simpleTracks.c +++ src/hg/hgTracks/simpleTracks.c @@ -3963,45 +3963,42 @@ sqlFreeResult(&sr); hFreeConn(&conn); slReverse(&itemList); slSort(&itemList, bedCmp); tg->items = itemList; } static void bedPlusLabelDrawAt(struct track *tg, void *item, struct hvGfx *hvg, int xOff, int y, double scale, MgFont *font, Color color, enum trackVisibility vis) /* Draw a single bed item at position. If vis is full, draw the associated label to the left * of the item. */ { struct bedPlusLabel *bpl = item; struct bed *bed = item; int heightPer = tg->heightPer; -int x1 = round((double)((int)bed->chromStart-winStart)*scale) + xOff; -int x2 = round((double)((int)bed->chromEnd-winStart)*scale) + xOff; -int w; - -// if x1 is calulated to be way off to the left, -// i.e. it has a negative number that will cause the item has a starting position off the screen, -// this may cause a problem that the item does not get displayed, so set x1 to 0 if it is negative. -if (x1 < 0 ) x1 = 0; +int s = max(bed->chromStart, winStart), e = min(bed->chromEnd, winEnd); +if (s > e) + return; +int x1 = round((s-winStart)*scale) + xOff; +int x2 = round((e-winStart)*scale) + xOff; +int w = x2 - x1; +if (w < 1) + w = 1; if (tg->itemColor != NULL) color = tg->itemColor(tg, bed, hvg); -w = x2-x1; -if (w < 1) - w = 1; hvGfxBox(hvg, x1, y, w, heightPer, color); // In full mode, draw bpl->label to the left of item: if (vis == tvFull) { int textWidth = mgFontStringWidth(font, bpl->label); hvGfxTextRight(hvg, x1-textWidth-2, y, textWidth, heightPer, color, font, bpl->label); } } static void bedPlusLabelMapItem(struct track *tg, struct hvGfx *hvg, void *item, char *itemName, char *mapItemName, int start, int end, int x, int y, int width, int height) /* Special mouseover text from item->label. (derived from genericMapItem) */ {