From f3cb65b5213857432862c00e9f1b6cc2df610021 Mon Sep 17 00:00:00 2001 From: Molly Lloyd Date: Fri, 12 Aug 2016 12:45:44 -0400 Subject: [PATCH] add integer overflow test --- js/data/bucket/symbol_bucket.js | 3 --- test/js/data/symbol_bucket.test.js | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/js/data/bucket/symbol_bucket.js b/js/data/bucket/symbol_bucket.js index 845432e2899..3df4216cf87 100644 --- a/js/data/bucket/symbol_bucket.js +++ b/js/data/bucket/symbol_bucket.js @@ -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; @@ -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) : []; @@ -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"); diff --git a/test/js/data/symbol_bucket.test.js b/test/js/data/symbol_bucket.test.js index c651cab237d..06c0227662d 100644 --- a/test/js/data/symbol_bucket.test.js +++ b/test/js/data/symbol_bucket.test.js @@ -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; @@ -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(); });