microsoft / Win2D

Win2D is an easy-to-use Windows Runtime API for immediate mode 2D graphics rendering with GPU acceleration. It is available to C#, C++ and VB developers writing apps for the Windows Universal Platform (UWP). It utilizes the power of Direct2D, and integrates seamlessly with XAML and CoreWindow.
http://microsoft.github.io/Win2D
Other
1.8k stars 284 forks source link

UWP app crashes when a big CanvasControl is created. #563

Closed gsantopaolo closed 6 years ago

gsantopaolo commented 6 years ago

Step to reproduce the issue:

`

    <InkCanvas Grid.Column="1" x:Name="inkCanvas"/>
</Grid>`

If you run the following app on a PC with a screen resolution of 1920x1080 at 96 dpi it works If you run the following app on a PC with a screen resolution of 3200x1800 at 168 dpi it crashes If you run the following app on a PC with a screen resolution of 2736x1824 at 192 dpi it crashes

By decreasing CanvasControl's width and height it does not crash any more. As you can understand when you develop a UWP application we target from small 4 or less inches all the way up to 84 inches with an unpredictable combinations of resolutions / dpi

A possible workaround for this issue should be to set the ForceSoftwareRenderer CanvasControl's property to True, but this is not acceptable when using the CanvasControl related to Ink because the ink experience becomes extremely lagging and far away of giving users a more personal experience.

All that said, is there a formula so it is possible to determine the maximum CanvasControl width and height based on screen resolution / dpi / (MaximumBitmapSizeInPixels) so that the application won't miserably crash?

Is there any chance that this behavior will change in the future?

Thanks a lot Gian Paolo

damyanp commented 6 years ago

This article covers the relationship between DIPS, pixels and DPI: http://microsoft.github.io/Win2D/html/DPI.htm

In your examples:

So in the 168 DPI case you're asking for a CanvasControl that's backed by a 17,500 x 10,500 pixel image source. MaximumBitmapSizeInPixels is likely to be around 16384, which explains this fails.

You can use a CanvasVirtualControl to support larger, virtualized surfaces.