You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Investigate NaN being produced internally during CRS work #2219
During the timeline below, it was hinted at in #2208 by @maheshj01, then investigated by @mootw, that NaN was being produced internally by the following method in MapCamera:
It appears that when this method is called with identical arguments, the result is NaN? However, for some reason, before #2182, this did not cause issues. This needs to be investigated.
The method itself also needs to be investigated - why is it the shape that it is? See comments in #2199 for more information. Does it make more sense for the method to return 1 instead of NaN or 0 when the inputs are the same?
Hi @JaffaKetchup — took a look since this is squarely in an area I work in (a snow-driving nav stack on flutter_map).
Root cause:getZoomScale(to, from) is crs.scale(to) / crs.scale(from). The default Epsg3857 extends CrsWithStaticTransformation, which doesn't override scale(), so it uses the base Crs.scale = 256 * math.pow(2, zoom). For normal zooms that's a finite number, so getZoomScale(z, z) is a clean 1.0 — the common case is fine. It only degenerates to NaN when scale(z) itself is 0, ±∞, or NaN (i.e. x/x with a degenerate x). Reproduced against the current code:
scale(1017) = Infinity → getZoomScale(1017, 1017) = NaN (∞/∞)
scale(-1100) = 0.0 → getZoomScale(-1100, -1100) = NaN (0/0)
scale(NaN) = NaN → getZoomScale(NaN, NaN) = NaN
getZoomScale(14, 14) = 1.0 (normal — fine)
On your suggestion (return 1 when the inputs are the same): it fixes the finite-extreme case and also catches ±infinity (since inf == inf is true) — but it misses the NaN case, because NaN == NaN is false in Dart, so the to == from guard is skipped and the NaN falls through. A complete guard would also short-circuit non-finite inputs (if (!toZoom.isFinite || !fromZoom.isFinite) return 1;).
That said, the more interesting question is where a NaN/extreme zoom comes from — getZoomScale(z, z) can't be NaN for a normal z (it's always 1.0), so the NaN-during-interaction reports (e.g. #2199) suggest a NaN or runaway zoom is entering the camera upstream, probably from gesture/animation math, and getZoomScale is just where it first surfaces. A guard here stops the crash; tracing the upstream NaN would stop it at the source.
Happy to put up a small PR with the guard + a regression test (I've got a local repro covering the identical-args finite/∞/NaN cases) if that'd be useful — or leave it to you. Whatever's easiest.
Activity
aki1770-del commentedon Jul 3, 2026
Hi @JaffaKetchup — took a look since this is squarely in an area I work in (a snow-driving nav stack on flutter_map).
Root cause:
getZoomScale(to, from)iscrs.scale(to) / crs.scale(from). The defaultEpsg3857extendsCrsWithStaticTransformation, which doesn't overridescale(), so it uses the baseCrs.scale=256 * math.pow(2, zoom). For normal zooms that's a finite number, sogetZoomScale(z, z)is a clean1.0— the common case is fine. It only degenerates to NaN whenscale(z)itself is0,±∞, orNaN(i.e.x/xwith a degeneratex). Reproduced against the current code:On your suggestion (return
1when the inputs are the same): it fixes the finite-extreme case and also catches±infinity(sinceinf == infistrue) — but it misses the NaN case, becauseNaN == NaNisfalsein Dart, so theto == fromguard is skipped and the NaN falls through. A complete guard would also short-circuit non-finite inputs (if (!toZoom.isFinite || !fromZoom.isFinite) return 1;).That said, the more interesting question is where a NaN/extreme zoom comes from —
getZoomScale(z, z)can't be NaN for a normalz(it's always1.0), so the NaN-during-interaction reports (e.g. #2199) suggest a NaN or runaway zoom is entering the camera upstream, probably from gesture/animation math, andgetZoomScaleis just where it first surfaces. A guard here stops the crash; tracing the upstream NaN would stop it at the source.Happy to put up a small PR with the guard + a regression test (I've got a local repro covering the identical-args finite/∞/NaN cases) if that'd be useful — or leave it to you. Whatever's easiest.