A customer reported that their program encountered rendering problems when they created elements that were a half billion pixels tall, and they wondered why this was happening.
A half billion pixels is an awful lot of pixels. At 96 pixels per inch, that gives you an element whose height is over 82 miles (132 km). There is no monitor that tall nor piece of paper that large.¹
The conceptual reason things break down with elements that large is that you have far exceeded any reasonable limits for element size. You have ventured into unexplored territory.
The practical reason that things break down is that XAML operates internally with single-precision IEEE floating point values. (For performance reasons, the internal calculations are performed only to single-precision accuracy even though the API surface exposes double-precision IEEE floating point. Attempts to revise the API to be less deceptive and expose the values as single-precision IEEE floating point values ran into compatibility problems.)
Single-precision IEEE floating point can represent exact integers up to approximately ±2²⁴ = ±16,777,216, and the customer’s 500,000,000-pixel-tall element is far beyond that. And even if the value could be represented exactly, the value is now so large that you have lost all fractional pixels, which will cause all sorts of rounding errors.
Since there is no screen large enough to display an entire 500,000,000-pixel tall element, you can shrink the element down to a size that is, say, only three times² the size of the user’s screen. If the user scrolls the viewport, you can adjust the element accordingly so that the visible portion of your virtual element remains realized.
¹ By some calculations, the largest possible PDF document is 381 km × 381 km. These calculations have, however, come into dispute.
² I chose “three times” because I believe that that is the factor used by XAML virtualizing control (like ListView) to determine the size of the realization window.
Did the customer explain why they had a half billion pixels tall element? Was it just a bug or was it intentional? (I am asking because, after reading this blog for a while now, I wouldn’t be surprised if it were intentional…)
It was definitely intentional. I believe they were creating a very large diagram. They didn’t say why they had a diagram that large. Maybe it’s a gigantic map, and the very large element is the “ocean” backdrop?
Circumference of the Earth is approximately 40,075,000 metres, 13 pixels/metre gives you ~521m pixels total, so it’s plausible. Just not at all smart.
Literally two decades ago, a program of mine used a bitmap that had approximately one pixel of height for every 100 clusters in a filesystem. Worked fine back in the day, but nowadays with multi-terabyte disks it’s probably another story.
If one wants more details on trying to explore the limits of PDFs, I think this is the standard account: https://alexwlchan.net/2024/big-pdf/
It turns out that some PDF readers either don’t follow the standards or interpret them differently, and so with them it’s possible to create a PDF which is interpreted as being a square with sides around 37 trillion light years long. As the article says, “Admittedly it’s mostly empty space, but so is the universe.”