Skip to content

Fix broken map on pitch=0 on some systems - #3740

Merged
mourner merged 1 commit into
masterfrom
fix-pitch-0
Dec 5, 2016
Merged

mourner merged 1 commit into
masterfrom
fix-pitch-0

Conversation

@mourner

@mourner mourner commented Dec 5, 2016

Copy link
Copy Markdown
Member

Fixes #2270 by making sure a floating point error does not accumulate into a broken projection matrix.

When pitch = 0, a Float32Array perspective matrix would end up with 1.5000001192092896, 1.5 as the last values, while Float64Array produces correct 1.5, 1.5. Empirically, I found that the first value never exceeds the second one with proper precision. When it does (which happens even with Float64Array on some systems), the map disappears. So while I don't fully grasp the math behind this, this hack seems to fix the pitch=0 bug.

cc @ansis @jfirebaugh @lucaswoj

Comment thread js/geo/transform.js
mat4.translate(m, m, [0, 0, -this.altitude]);

// a hack around https://github.com/mapbox/mapbox-gl-js/issues/2270
m[14] = Math.min(m[14], m[15]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The rewards of this not-100%-understood fix outweigh the severity of the bug & risks of the fix in my mind.

Out of curiosity, is there any intuitive meaning of elements 14 and 15 in the transformation matrix? Can we anticipate any cases where elements 14 and 15 might end up with very different values? cc @ansis

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There seem to be no intuitive meaning since the perspective projection math is a bit involved, but at this point of position matrix calculation, m[15] always equals the altitude value (1.5), and m[14] represents translation along Z axis (which always seems to be <=1.5).

@mourner
mourner merged commit 764f80a into master Dec 5, 2016
@mourner
mourner deleted the fix-pitch-0 branch December 5, 2016 23:07
ansis added a commit that referenced this pull request Dec 13, 2016
This should fix the issue behind #2270 and remove the need for the hack
added in #3740.
ansis added a commit that referenced this pull request Dec 13, 2016
This should fix the issue behind #2270 and remove the need for the hack
added in #3740.
ansis added a commit that referenced this pull request Dec 13, 2016
This should fix the issue behind #2270 and remove the need for the hack
added in #3740.
@ansis ansis mentioned this pull request Dec 13, 2016
7 tasks done
ansis added a commit that referenced this pull request Dec 14, 2016
This should fix the issue behind #2270 and remove the need for the hack
added in #3740.
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.

Map does not render unless pitch is set and map is "tilted"

2 participants