Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add warning for integer overflow in the SymbolInstancesArray #2966

Merged
merged 6 commits into from Aug 16, 2016

Conversation

mollymerp
Copy link
Contributor

@mollymerp mollymerp commented Aug 9, 2016

first stab at warning language 😁
the condition is based on the assumption that the max valid 16 bit unsigned integer is 65535

Checklist

ref #2907

this branch

buffer: 1,005 ms
fps: 60 fps
frame-duration: 7.8 ms, 0% > 16ms
query-point: 0.45 ms
query-box: 36.59 ms
geojson-setdata-small: 4 ms
geojson-setdata-large: 107 ms

master

buffer: 909 ms
fps: 60 fps
frame-duration: 7.7 ms, 0% > 16ms
query-point: 0.41 ms
query-box: 40.46 ms
geojson-setdata-small: 6 ms
geojson-setdata-large: 97 ms

@lucaswoj
Copy link
Contributor

lucaswoj commented Aug 9, 2016

Language looks good to me!

Add a couple test cases and :shipit:

@lucaswoj
Copy link
Contributor

lucaswoj commented Aug 9, 2016

Apologies for the failed CI build. This happened while we were upgrading our CI infrastructure per #2958. If you rebase on master and push, everything should be 🍏 and much more stable!

@mollymerp mollymerp force-pushed the integer-overflow-warning branch 3 times, most recently from 9c3acda to 831c268 Compare August 12, 2016 16:47
@mollymerp
Copy link
Contributor Author

test added @lucaswoj ty for the constant suggestion! 🎈

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend using sinon.spy on util.warnOnce instead of monkey-patching console.warn. Sinon gives us a nicer API for making assertions about what warning messages have been emitted, gives us easy restoration of the original method, and allows real console.warn messages to make their way to the console where they belong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this approach from here after searching for other tests that were looking for warnings. I will look into sinon for a refactor.

@mollymerp
Copy link
Contributor Author

@lucaswoj I implemented your suggestions, but should the warning be actually printing to the console when I run npm test? Or is there another way to suppress that just for this test?

@lucaswoj
Copy link
Contributor

should the warning be actually printing to the console when I run npm test?

Ideally not. You should be able to work around this by replacing sinon.spy with sinon.stub.

@mollymerp
Copy link
Contributor Author

sinon.stub implemented.

🚢 on ✅ ?

@@ -594,6 +599,8 @@ 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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work, because this.MAX_QUADS refers to the instance variable, while SymbolBucket.MAX_QUADS is a static property of SymbolBucket.

@mollymerp
Copy link
Contributor Author

good call @mourner -- should I reset the value of SymbolBucket.MAX_QUADS after the test completes?

@mourner
Copy link
Member

mourner commented Aug 16, 2016

@mollymerp yes, well noted!

@lucaswoj
Copy link
Contributor

Looks good :shipit:

@mollymerp mollymerp merged commit 8a8460c into master Aug 16, 2016
@mollymerp mollymerp deleted the integer-overflow-warning branch August 16, 2016 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants