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

[WinUI3] Viewport3DX crash to a white background after nagivating to another page #2059

Open
noudavinci opened this issue Dec 1, 2023 · 4 comments

Comments

@noudavinci
Copy link

Hi, I'm having a trouble with my WinUI 3 application: I have a <hx:Viewport3DX> inside one of my pages. At the first time navigating to that page, things work well. But after I switch to another page, then switch back, the viewport becomes white, and I can't react to the viewport anymore until I restart the program.
Before switching to another page:
image
After switching to another page:
image
the code I used to display the viewport:

<hx:Viewport3DX x:Name="ViveTracker_Viewport"
                Grid.Column="0" Grid.Row="0"
                Margin="0,0,11,0"
                Camera="{x:Bind MainVM.Camera}"
                EffectsManager="{x:Bind MainVM.EffectsManager}"
                BackgroundColor="#1d1d1d"
                EnableDeferredRendering="True"
                FXAALevel="Medium"
                EnableDpiScale="True">
    <hx:DirectionalLight3D Direction="{x:Bind MainVM.Camera.LookDirection}" Color="White" />
    <hx:Element3DPresenter x:Name="Preview_RootElements" Content="{x:Bind MainVM._root}" />
</hx:Viewport3DX>

That page has been cached using NavigationCacheMode="Required". All the content of the Viewport is delivered from an instance of class TrackingSpaceViewport containing camera, effectsmanager,...
I tried to turn off page caching with NavigationCacheMode="Disabled" but everytime I reopen that page, the memory keeps increasing and I think there is a memory leak in Viewport3DX (tested by commenting the viewport3dx code and it's gone).
Can anyone suggest me how to fix this?

@holance
Copy link
Member

holance commented Dec 2, 2023

Check whether an new effect manager being created every time page is switched.

@noudavinci
Copy link
Author

Thanks for your answer, but no Effect Manager being created. The Effect Manager is created once the instance of TrackingSpaceViewport is created, when the program starts. That instance lives with the program until the user closes them. I suspect that the render engine of the Viewport3DX will be terminated when the page switched, but does not being started when I switch back to the viewport page, don't know whether it's true or not. I tried searching online for the concept of interacting between WinUI and the HelixToolkit in terms of UI rendering, couldn't find anything in detail.
Temporarily, I put the Viewport3DX in another indenpendent window, so it will not be useless after switching to another page. But I really want to put it inside the navigation page.

@holance
Copy link
Member

holance commented Dec 5, 2023

Could you create a sample project for me to debug?

@isenbergd
Copy link

Hi, I ran into the same issue. I was able to "solve" it by listening to the SizeChanged Event of the control and setting the width of the viewport to a fixed value and immediately back to "double.NaN".
This somehow forces a correct refresh.

InitializeComponent();
SizeChanged += (sender, args) =>
{
    PositioningViewport.Width = 800;
    DispatcherQueue.TryEnqueue(() => PositioningViewport.Width = double.NaN);
};

In your case PositioningViewport is ViveTracker_Viewport

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

No branches or pull requests

3 participants