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

Memory error reading bug when using ContextMenuMode="SecondWindow" for tray icons in Windows AppSdk 1.4.230822000 version #107

Open
BlameTwo opened this issue Sep 11, 2023 · 9 comments
Labels
bug Something isn't working

Comments

@BlameTwo
Copy link

Describe the bug

Error: Exception thrown at 0x00007FFDC50BDE84 (Microsoft. UI. Windowing. Core. dll) (located in App1. exe): 0xC000000 5: An access violation occurred while reading position 0x0000000000030.

Steps to reproduce the bug

In WIndowsAppSdk (v1.4.230822000), use the TaskbarIcon of H.NotifyIcon. WinUI (v2.0.116) to create a tray icon, then set ContextMenuMode="SecondWindow", and finally trigger Exception throw at 0x00007FFDC50BDE84 (Microsoft. UI. Windowing. Core. dll) (located in App. WinUI3 Exe): 0xC000000 5: An access Violation occurred while reading position 0x000000000030

Expected behavior

Should be created correctly and functioning properly

Screenshots

No response

NuGet package version

WindowsAppSdk (1.4.230822000)
H.NotifyIcon(2.0.116)

Platform

WinUI

IDE

Visual Studio 2022-preview

Windows Version

Windows 11

WindowsAppSDK Version

Other

WindowsAppSDK Type

None

Manifest

No response

Additional context

No response

@BlameTwo BlameTwo added the bug Something isn't working label Sep 11, 2023
@BlameTwo
Copy link
Author

@HavenDV

@HavenDV
Copy link
Owner

HavenDV commented Sep 14, 2023

Sorry, I now have time issues and don’t have access to a Windows machine. I had problems running WinUI on a virtual machine inside Parallels Desktop arm64
SecondWindow is experimental in nature and has a lot of winapi calls to implement transparency and borderless window, and so it's quite time consuming to test all the options and fix it for now for me.
I'd be happy to accept PR if you're interested in doing it. The WinUI code for SecondWindow is concentrated in one file and, I hope, is quite clear - https://github.com/HavenDV/H.NotifyIcon/blob/master/src/libs/H.NotifyIcon.Shared/TaskbarIcon.ContextMenu.WinUI.SecondWindow.cs

@KarelChanivecky
Copy link

It actually crashes when instantiating a new window here:
In TaskbarIcon.ContextMenu.WinUI.SecondWindow.cs
image

I am not very experienced with .net, but I think this likely is a runtime bug. Instantiating without passing any arguments also results in a crash.

@HavenDV
Copy link
Owner

HavenDV commented Sep 14, 2023

It would be great if someone took the time to check if rolling back to one of the previous versions of WindowsAppSDK helps

@KarelChanivecky
Copy link

1.3 works. We got some other issue with 1.3 so it would've been nice if this worked, but that's life.

I tried the popup message mode, but it seems that the click events aren't being triggered? Do you have a clue on that?

The active window mode works, but it renders behind the system tray blob.

@BlameTwo
Copy link
Author

BlameTwo commented Sep 19, 2023

In the latest package version, I found that this issue still occurs in the debugging mode of Visual Studio 2022, but I tried to run it directly without debugging and found that it also has issues.
And I added global exception capture in the App. xaml file, which doesn't seem to affect the program's operation, but it will hinder me from debugging the application.

@Jimex
Copy link

Jimex commented Oct 8, 2023

Same problem here, the application crashes in debugging mode after upgrading the WindowsAppSDK to 1.4. It worked fine with 1.3.

@tibitoth
Copy link

Please try to disable In app toolbar in VS

@Jimex
Copy link

Jimex commented Oct 26, 2023

The temporary solution is to build the ContextFlyout programmatically and not assign it to the TrayIcon control.

            var menuFlyout = new MenuFlyout();
            var showHideWinCmd = new XamlUICommand()
            {
                Label = TranslateUtils.Translate("menu_show_hide_window"),
                Description = TranslateUtils.Translate("menu_show_hide_window"),
                IconSource = new SymbolIconSource() { Symbol = Symbol.OpenPane },

            };
            showHideWinCmd.ExecuteRequested += ShowHideWindowCommand_ExecuteRequested;
            menuFlyout.Items.Add(new MenuFlyoutItem()
            {
                Command = showHideWinCmd
            });

            var exitAppCmd = new XamlUICommand()
            {
                Label = TranslateUtils.Translate("menu_exit_application"),
                Description = TranslateUtils.Translate("menu_exit_application"),
                IconSource = new SymbolIconSource() { Symbol = Symbol.ClosePane },

            };
            showHideWinCmd.ExecuteRequested += ExitApplicationCommand_ExecuteRequested;
            menuFlyout.Items.Add(new MenuFlyoutItem()
            {
                Command = exitAppCmd
            });

            TrayIcon.LeftClickCommand = showHideWinCmd;
#if !DEBUG
            TrayIcon.ContextFlyout = menuFlyout;
#endif            

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants