maui icon indicating copy to clipboard operation
maui copied to clipboard

[Windows, 9.0 Preview 7] Every quit and exit method throws an exception

Open janne-hmp opened this issue 1 year ago • 3 comments
trafficstars

Description

I've been trying to exit my .NET MAUI 9.0 Windows application cleanly, but it seems that every exit or quit method throws an exception (at least so in .NET MAUI 9.0 Preview 7). The exceptions are different in each case, though. I tried with and without MainThread.BeginInvokeOnMainThread in the case this were a threading issue, but the results are the same either way.

Microsoft.Maui.Controls.Application.Exit():

image

Application.Current.Quit():

image

Environment.Exit(0):

image

What is the appropriate way to close a MAUI Windows app when the user wants to close it, e.g., by pressing a Quit button on the app's UI?

Steps to Reproduce

  1. Build and start GnollHackM for Windows in Debug mode
  2. Press Exit on the MainPage.
  3. Any of the aforementioned exit or quit calls throws an exception

Link to public reproduction project repository

https://github.com/hyvanmielenpelit/GnollHack

Version with bug

9.0.0-preview.7.24407.4

Is this a regression from previous behavior?

No

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows 10.0.22631

Did you find any workaround?

No, but the exception crashes the app, so it sort of does the trick, but SentrySDK reports the crash so we get a huge number of crash exceptions reported.

Relevant log output

No response

janne-hmp avatar Aug 28 '24 15:08 janne-hmp

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

github-actions[bot] avatar Aug 28 '24 15:08 github-actions[bot]

Interestingly, this seems to happen only when the app is in full screen mode. The exception is not thrown in WindowedMode. Full screen mode is implemented via:

                        bool maximizeWindow = !Preferences.Get("WindowedMode", false);
                        if(maximizeWindow)
                        {
                            window.ExtendsContentIntoTitleBar = false;
                            switch (appWindow.Presenter)
                            {
                                case Microsoft.UI.Windowing.OverlappedPresenter overlappedPresenter:
                                    overlappedPresenter.SetBorderAndTitleBar(false, false);
                                    overlappedPresenter.Maximize();
                                    break;
                            }
                        }

I did also test this with default Maui app in full screen mode, and at least Environment.Exit(0) does not work in full screen there, similar to my app. However, by contrast, Application.Current.Quit seems to work without exception, so there may be more than just the full screen mode in my app's setup that causes the crash.

janne-hmp avatar Aug 28 '24 17:08 janne-hmp

Hi @janne-hmp I couldn't repro this issue using the default MAUI app in full screen mode (not repro for both Environment.Exit(0) and Application.Current.Quit ) on VS 17.12 P3 with MAUI: 9.0.0-rc.2.24503.2 & 9.0.0-preview.7.24407.4. Can you share your simple sample that can repro this issue?

CathyZhu0110 avatar Oct 25 '24 06:10 CathyZhu0110

Hey @janne-hmp!

Would you be able to provide a more concise reproduction?

I appreciate your involvement with this and how you report issues, however the one thing that proves a bit difficult for us is that your linked repository is huge and that makes it hard to determine all the moving parts for a potential issue. That in turn, makes it hard to determine if something is happening in the .NET MAUI SDK or maybe something in your own app code.

Could we please ask you to lift the code involved into a separate project so we can look at only the code that shows this issue and not all the rest of your amazing game. That will make it easier for us to look at this and potentially fix it faster, but also it might make more clear to you what you are doing in your code and how to change it or workaround it.

That would be really amazing and helpful, thank you! Also for this one in this case, there has been a couple of new releases, also let us know if this is still happening in the latest version. Thank you!

jfversluis avatar Oct 28 '24 10:10 jfversluis

Hi, let me look into this soon. I could even make an easily buildable copy of the Windows version of the game in another repository. I've been travelling a bit lately, so haven't been able to work on this for the past couple of weeks, but should have more time pretty soon.

janne-hmp avatar Oct 28 '24 11:10 janne-hmp

Hi, since I don't know where the problem comes from, I now created a version of GnollHack that should build somewhat straightforwardly: https://github.com/hyvanmielenpelit/GnollHackMAUIEasyBuild. All you need to do is to follow the instructions in the README file to unzip the sound bank files from Releases to the right folders (too big to be directly in the repository), after which the project should more or less build immediately, at least for Windows, but also most likely for Android and iOS. I had to run dotnet restore to get things working first, but this is noted in the instructions

I will also update this issue's reproduction repository. Let me know if you run into any problems.

janne-hmp avatar Oct 28 '24 17:10 janne-hmp

Hi, since I don't know where the problem comes from, I now created a version of GnollHack that should build somewhat straightforwardly: https://github.com/hyvanmielenpelit/GnollHackMAUIEasyBuild. All you need to do is to follow the instructions in the README file to unzip the sound bank files from Releases to the right folders (too big to be directly in the repository), after which the project should more or less build immediately, at least for Windows, but also most likely for Android and iOS. I had to run dotnet restore to get things working first, but this is noted in the instructions

I will also update this issue's reproduction repository. Let me know if you run into any problems.

Hi @janne-hmp Thanks for providing a version which can easily build, I can debug succeeded now, while I still couldn't repro this issue on VS 17.12 P3 with MAUI: 9.0.0-rc.2.24503.2 & 9.0.0-preview.7.24407.4. Can you try again and see whether you can still repro using latest build?

CathyZhu0110 avatar Nov 01 '24 09:11 CathyZhu0110

We tried this on another computer, too, and with that we found that at least disabling Hot Reload may help causing the issue. (We have disabled it due to performance and other issues.) If that alone does not make the exception to appear, then I would suggest trying a completely fresh install of Visual Studio 2022 on a separate test computer that does not have special Microsoft testing setups. Our setup is:

  • Visual Studio 2022 Preview 5.0,
  • .NET MAUI 9.0 RC2
    • SDK 9.0.100-rc.2.24474.11
    • maui-windows workload 9.0.0-rc.2.24503.2/9.0.100-rc.2 / SDK 9.0.100-rc.2, VS 17.12.35417.141, VS 17.11.35327.3, VS 17.9.34902.65
    • many packages are 9.0.0-rc.2.24473.5
  • SkiaSharp 3.0 Preview 5.4.

To disable Hot Reload in this case, please disable WinUI XAML Hot Reload in Options

Image

and then Start Debugging Windows Machine. When the game starts, press Exit button, and you should see roughly the following:

Image

janne-hmp avatar Nov 01 '24 13:11 janne-hmp

This issue has been verified and can repro (To repro, need to disable xaml hot reload) using Visual Studio 17.12.0 Preview 5(9.0.0-rc.2.24503.2, [9.0.0-preview.7.24407.4), while works fine on 9.0.0-preview.6.24327.7 and latest nightly build 9.0.10-ci.net9.24553.1

CathyZhu0110 avatar Nov 04 '24 07:11 CathyZhu0110

Hi @janne-hmp. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.