Skip to content

Commit

Permalink
add integer overflow test
Browse files Browse the repository at this point in the history
  • Loading branch information
Molly Lloyd committed Aug 14, 2016
1 parent 13a410d commit f3cb65b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 0 additions & 3 deletions js/data/bucket/symbol_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ SymbolBucket.prototype.populateArrays = function(collisionTile, stacks, icons) {
};

SymbolBucket.prototype.addFeature = function(lines, shapedText, shapedIcon, feature) {
console.log(arguments);
var layout = this.layer.layout;

var glyphSize = 24;
Expand Down Expand Up @@ -570,7 +569,6 @@ SymbolBucket.prototype.addSymbolInstance = function(anchor, line, shapedText, sh
textBoxScale, textPadding, textAlongLine,
iconBoxScale, iconPadding, iconAlongLine, globalProperties, featureProperties) {


var glyphQuadStartIndex, glyphQuadEndIndex, iconQuadStartIndex, iconQuadEndIndex, textCollisionFeature, iconCollisionFeature, glyphQuads, iconQuads;
if (shapedText) {
glyphQuads = addToBuffers ? getGlyphQuads(anchor, shapedText, textBoxScale, line, layer, textAlongLine) : [];
Expand Down Expand Up @@ -601,7 +599,6 @@ SymbolBucket.prototype.addSymbolInstance = function(anchor, line, shapedText, sh

var iconBoxStartIndex = iconCollisionFeature ? iconCollisionFeature.boxStartIndex : this.collisionBoxArray.length;
var iconBoxEndIndex = iconCollisionFeature ? iconCollisionFeature.boxEndIndex : this.collisionBoxArray.length;

if (iconQuadEndIndex > this.MAX_QUADS) util.warnOnce("Too many symbols being rendered in a tile. See https://github.com/mapbox/mapbox-gl-js/issues/2907");
if (glyphQuadEndIndex > this.MAX_QUADS) util.warnOnce("Too many glyphs being rendered in a tile. See https://github.com/mapbox/mapbox-gl-js/issues/2907");

Expand Down
15 changes: 15 additions & 0 deletions test/js/data/symbol_bucket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ test('SymbolBucket', function(t) {

var bucketA = bucketSetup();
var bucketB = bucketSetup();
var bucketC = bucketSetup();

// add feature from bucket A
var a = collision.grid.keys.length;
Expand All @@ -72,5 +73,19 @@ test('SymbolBucket', function(t) {
var b2 = collision.grid.keys.length;
t.equal(a2, b2, 'detects collision and does not place feature');

// Use a custom console.warn to count warnings
var numWarnings = 0;
var warn = console.warn;
console.warn = function(warning) {
if (warning.includes("Too many symbols being rendered in a tile.") || warning.includes("Too many glyphs being rendered in a tile.")) {
numWarnings++;
}
};

bucketC.MAX_QUADS = 14;
t.equal(bucketC.populateArrays(collision, stacks), undefined);
t.equal(numWarnings, 2, 'integer overflow warning is triggered when glyph and/or symbol quad exceeds MAX_QUADS');
// Put it back
console.warn = warn;
t.end();
});

0 comments on commit f3cb65b

Please sign in to comment.