AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.42k stars 2.2k forks source link

Unable to create child window for native control host #15354

Open rdeusser opened 5 months ago

rdeusser commented 5 months ago

Describe the bug

Basically #8609, except the solution already exists in the project. I’m using Ryujinx and I only get this exception when I enable mods. It’s confusing because it seems like the issue in #8609 has a singular cause, but it appears there’s other ways to make it crop up. Is there a definitive cause for this exception? The stacktrace is incredibly unhelpful because it doesn’t show me anything in Ryujinx outside of ‘BuildAvaloniaApp’. I can post a stacktrace later. I’m on mobile at the moment.

To Reproduce

Expected behavior

Potentially a crash that has nothing to do with Avalonia, otherwise a working game.

Avalonia version

11.0.10

OS

Windows

Additional context

I’ll add more here later when I can get back to my computer.

maxkatz6 commented 5 months ago

We need a proper minimal repro to even try to help with this issue. We don't have dev capacity to investigate Ryujinx source code and repro this issue with a dumped (legitimately) game images.

TSRBerry commented 5 months ago

I can at least provide a stack trace for this issue for now, since a person with this issue uploaded a log in our support channels.

Stack trace ``` Unhandled exception caught: System.InvalidOperationException: Unable to create child window for native control host. Application manifest with supported OS list might be required. at Avalonia.Win32.Win32NativeControlHost.DumbWindow..ctor(Boolean , Nullable`1 ) at Avalonia.Win32.Win32NativeControlHost.CreateNewAttachment(Func`2) at Avalonia.Controls.NativeControlHost.UpdateHost() at Avalonia.Controls.NativeControlHost.OnAttachedToVisualTree(VisualTreeAttachmentEventArgs) at Avalonia.Visual.OnAttachedToVisualTreeCore(VisualTreeAttachmentEventArgs) at Avalonia.Layout.Layoutable.OnAttachedToVisualTreeCore(VisualTreeAttachmentEventArgs) at Avalonia.Input.InputElement.OnAttachedToVisualTreeCore(VisualTreeAttachmentEventArgs) at Avalonia.Controls.Control.OnAttachedToVisualTreeCore(VisualTreeAttachmentEventArgs) at Avalonia.Visual.SetVisualParent(Visual) at Avalonia.Visual.SetVisualParent(IList, Visual ) at Avalonia.Visual.VisualChildrenChanged(Object sender, NotifyCollectionChangedEventArgs e) at Avalonia.Collections.AvaloniaList`1.Add(T) at Avalonia.Controls.Presenters.ContentPresenter.UpdateChild(Object) at Avalonia.Controls.Presenters.ContentPresenter.UpdateChild() at Avalonia.Controls.Presenters.ContentPresenter.ApplyTemplate() at Avalonia.Layout.Layoutable.MeasureCore(Size) at Avalonia.Layout.Layoutable.Measure(Size) at Avalonia.Layout.Layoutable.MeasureOverride(Size) at Avalonia.Layout.Layoutable.MeasureCore(Size) at Avalonia.Layout.Layoutable.Measure(Size) at Avalonia.Layout.LayoutHelper.MeasureChild(Layoutable, Size, Thickness, Thickness) at Avalonia.Controls.Presenters.ContentPresenter.MeasureOverride(Size) at Avalonia.Layout.Layoutable.MeasureCore(Size) at Avalonia.Layout.Layoutable.Measure(Size) at Avalonia.Layout.LayoutManager.Measure(Layoutable) at Avalonia.Layout.LayoutManager.ExecuteMeasurePass() at Avalonia.Layout.LayoutManager.InnerLayoutPass() at Avalonia.Layout.LayoutManager.ExecuteLayoutPass() at Avalonia.Layout.LayoutManager.ExecuteQueuedLayoutPass() at Avalonia.Media.MediaContext.FireInvokeOnRenderCallbacks() at Avalonia.Media.MediaContext.RenderCore() at Avalonia.Media.MediaContext.Render() at Avalonia.Threading.DispatcherOperation.InvokeCore() at Avalonia.Threading.DispatcherOperation.Execute() at Avalonia.Threading.Dispatcher.ExecuteJob(DispatcherOperation) at Avalonia.Threading.Dispatcher.ExecuteJobsCore(Boolean) at Avalonia.Threading.Dispatcher.Signaled() at Avalonia.Win32.Win32Platform.WndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam) at Avalonia.Win32.Interop.UnmanagedMethods.DispatchMessage(MSG&) at Avalonia.Win32.Win32DispatcherImpl.RunLoop(CancellationToken) at Avalonia.Threading.DispatcherFrame.Run(IControlledDispatcherImpl) at Avalonia.Threading.Dispatcher.PushFrame(DispatcherFrame) at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken) at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[]) at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime(AppBuilder, String[], Action`1 ) at Ryujinx.Ava.Program.Main(String[] args) in D:\a\Ryujinx\Ryujinx\src\Ryujinx\Program.cs:line 52 ```

I'm currently investigating this myself, so I'll follow up if I figure out more about this issue.

I feel like the error message should maybe include that Handle is a null pointer? https://github.com/AvaloniaUI/Avalonia/blob/76a1c70758884abcebc9e3665aa08290a841efa4/src/Windows/Avalonia.Win32/Win32NativeControlHost.cs#L98-L99

TSRBerry commented 5 months ago

Since CreateWindowExW sets an error code, it would be nice if the exceptions could also include it with the associated error message.

See Marshal.GetLastPInvokeError() and Marshal.GetLastPInvokeErrorMessage()

timunie commented 5 months ago

@TSRBerry maybe you can file a PR to improve the error message as you seem to know where to do it

maxkatz6 commented 5 months ago

@TSRBerry you are most likely missing app.manifest file, as it's mentioned in the error message.

TSRBerry commented 5 months ago

Well no, see the issue description and the app.manifest file here.

maxkatz6 commented 5 months ago

In this case, can't help much. GetLastPInvokeErrorMessage can be an inner exception, yes.