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

Crash when 3D transform is behind camera #164

Closed
JohannesMoersch opened this issue Sep 25, 2015 · 9 comments
Closed

Crash when 3D transform is behind camera #164

JohannesMoersch opened this issue Sep 25, 2015 · 9 comments

Comments

@JohannesMoersch
Copy link

If the result of any 3D transform involving a CreatePerspective call that places part or all of the image I am drawing behind the camera, I get this exception:

The graph could not be rendered with the context's current tiling settings. (Exception from HRESULT: 0x88990027)

For instance, if I try to call draw image on a 3D transform that has this matrix:
Matrix4x4.CreatePerspective(0.001333f, 0.001333f, 1.0f, 1500.0f)
It will immediately crash. If I add a translate before the create perspective that moves to any negative value on Z, no problem. Then, after doing this transform, if I add a rotate before the translate that rotates the image towards the camera until the top is behind the camera, it will crash with this same exception.

Any idea what's up?

@shawnhar shawnhar added the bug label Sep 25, 2015
@damyanp
Copy link
Member

damyanp commented Sep 29, 2015

Hi - I'm having some trouble reproducing this issue. Can you share some code that demonstrates the problem please?

Thanks.

@JohannesMoersch
Copy link
Author

Sorry for the delayed response. The following produces the error for me. This is a Windows 10 Universal Application.

MainPage.xaml

<Page x:Class="TestUniversalApp.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:canvas="using:Microsoft.Graphics.Canvas.UI.Xaml">

    <canvas:CanvasAnimatedControl Draw="CanvasAnimatedControl_Draw" CreateResources="CanvasAnimatedControl_CreateResources" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />

</Page>

MainPage.xaml.cs

using System;
using System.Numerics;
using System.Threading.Tasks;
using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Effects;
using Windows.Foundation;
using Windows.UI.Xaml.Controls;

namespace TestUniversalApp
{
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            InitializeComponent();
        }

        CanvasBitmap _bitmap;
        Transform3DEffect _transform;

        private void CanvasAnimatedControl_CreateResources(Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.CanvasCreateResourcesEventArgs args)
        {
            args.TrackAsyncAction(Load(sender).AsAsyncAction());
        }

        private async Task Load(ICanvasResourceCreator canvas)
        {
            _bitmap = await CanvasBitmap.LoadAsync(canvas, "Assets/TestImage.jpg");
            _transform = new Transform3DEffect() { Source = _bitmap };
        }

        private void CanvasAnimatedControl_Draw(Microsoft.Graphics.Canvas.UI.Xaml.ICanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedDrawEventArgs args)
        {
            _transform.TransformMatrix = Matrix4x4.CreatePerspective(0.001333f, 0.001333f, 1.0f, 1500.0f);
            args.DrawingSession.DrawImage(_transform, new Rect(new Point(0, 0), sender.Size), new Rect(new Point(0, 0), _bitmap.Size));
        }
    }
}

@damyanp
Copy link
Member

damyanp commented Oct 5, 2015

Can you share TestImage.jpg (or maybe just the size of this image) As it is, I'm not seeing a repro.

Can you tell me some more about what machine you are seeing this on? PC or mobile?

@JohannesMoersch
Copy link
Author

Image size seems to contribute because a smaller image did not cause the problem. TestImage.jpg is 3840x2160 and I'm testing this on a Thinkpad W540 with an Nvidia Quadro K1100M. Changing the preferred graphics processor in the nvidia drivers doesn't fix the issue (and earlier testing indicated that this option actually does change which processor is doing the rendering - I watched GPU-Z load graphs to check this).

@damyanp
Copy link
Member

damyanp commented Oct 5, 2015

Still not luck reproducing this I'm afraid. Would you be able to share a complete project that reproduces this please? Thanks!

@damyanp
Copy link
Member

damyanp commented Oct 5, 2015

Ah! I thought I'd try one last thing before moving on. The missing piece here is that the display needs to be set to high DPI. So I can now repro if I set the scaling to 125%. I've enough to start digging more on our end. Thanks!

@JohannesMoersch
Copy link
Author

Awesome! Didn't think to mention DPI. I have my displays at 150%.

@damyanp
Copy link
Member

damyanp commented Oct 7, 2015

This is an issue on the platform when the 3D transform causes the image to be clipped by the near plane.

As this fix for this will be done in the OS (rather than in Win2D) I'm going to close this issue.

In the meantime, I'm afraid the best advice here is to take steps in your app to avoid this situation arising.

Thanks for bringing this to our attention!

@damyanp damyanp closed this as completed Oct 7, 2015
@13thsymphony
Copy link
Member

For a little more detail, this issue gets hit when two conditions are true:

  1. Near plane clipping as a result of your 3D transform
  2. Direct2D internally attempting to render to a very large intermediate texture (i.e. larger than the Direct3D maximum texture size, which for Windows 10 is generally at least 4096*4096)

Part 2 is an internal implementation detail, so it's hard to guarantee that it won't be hit. You can mitigate by using smaller inputs (i.e. your 4K image) or by ensuring that the output of any specific effect, such as the 3D transform, would not result in a rendered image that is greater than 4096*4096.

The OS platform team is investigating this bug for resolution in a future release of Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants