BartoszCichecki / LenovoLegionToolkit

Lightweight Lenovo Vantage and Hotkeys replacement for Lenovo Legion laptops.
GNU General Public License v3.0
4.56k stars 220 forks source link

Tray icon issues / Object reference not set to an instance of an object. #673

Closed Dampfinchen closed 10 months ago

Dampfinchen commented 1 year ago

Version

2.11.2

OS

Windows 11 Build 22621

Device

Legion Y540 15IRH

BIOS version

LENOVO BHCN45WW

What's wrong?

When trying to open Lenovo Toolkit from tray icon, it randomly crashes with the following error:

issue

Note: this does not happen all the time. It's pretty rare and random, which makes it hard to log.

How to reproduce the bug?

Open Toolkit from the system tray.

Very hard to reproduce, as its happening on rare and random occasions.

What is the behavior that you expected?

That it opens normally all the time.

Logs

For this issue to be logged, I'd have to enable the logger for a long time because it happens so rarely.

Do you have Lenovo software installed?

Did you disable any Lenovo software using Lenovo Legion Toolkit?

Additional information

No response

BartoszCichecki commented 1 year ago

Update and check again.

BartoszCichecki commented 1 year ago

Related #662

Dampfinchen commented 1 year ago

Update and check again.

Unfortunately still happens with 2.12.0

BartoszCichecki commented 1 year ago

I cannot reproduce this bug. I know that tray handling is a little messy in recent versions of Windows 10 and 11, so I can suggest that you make sure you have all latest updates installed.

BartoszCichecki commented 1 year ago

As a side note, if anyone knows how could I work around this problem (and the problem from the issue linked above) let me know. PRs are also welcome.

Dampfinchen commented 1 year ago

I cannot reproduce this bug. I know that tray handling is a little messy in recent versions of Windows 10 and 11, so I can suggest that you make sure you have all latest updates installed.

Yeah it's a bit hard to reproduce as its so random. You have to use it for quite a while and perhaps also use an action that restarts the GPU when disconnecting AC (which I'm using extensively as it's the most useful feature of LLT imo when using an external monitor. So whenever I unplug my laptop from AC and the external monitor, the dGPU gets disabled automatically which is very convenient.) You could try recreating that environment if you have an external monitor. @BraveSam do you use the program in a similar fashion?

I can say my OS has the latest updates.

I also can say I haven't had the issue with previous LTT versions, like 2.8. So perhaps there is something new that was added in 2.11 that lead to this issue.

BartoszCichecki commented 1 year ago

So perhaps there is something new that was added in 2.11 that lead to this issue.

The error logs attached in the other ticket that is linked above indicate it has something to do with showing the popup when you hover over the tray icon.

The troubling thing is that the error originates somewhere deep in the Windows APIs so I can't make a workaround for it. I could make a build without the tray popup (or an option to turn it off) and see if that fixes the issue.

The popup was added in 2.11 so the correlation is clear; I am just not sure why Windows causes the crash here.

Dampfinchen commented 1 year ago

So perhaps there is something new that was added in 2.11 that lead to this issue.

The error logs attached in the other ticket that is linked above indicate it has something to do with showing the popup when you hover over the tray icon.

The troubling thing is that the error originates somewhere deep in the Windows APIs so I can't make a workaround for it. I could make a build without the tray popup (or an option to turn it off) and see if that fixes the issue.

The popup was added in 2.11 so the correlation is clear; I am just not sure why Windows causes the crash here.

Yes, that was my suspicion as well. A shame because the new popup is really nice looking and informative... :/ I will make sure to test your future build then. As that would be a long term test, uploading it as 2.12.1 would make sense with an option integrated to turn the popup off.

BartoszCichecki commented 1 year ago

Here is a test build where you can disable the custom tray icon tooltip, since it's not a very common bug, here is how to disable it:

  1. Go to %LOCALAPPDATA%\LenovoLegionToolkit
  2. Create args.txt file in there (if you already have it edit)
  3. Paste --disable-tray-tooltip (if you have other parameters, there should be 1 per line)
  4. Start LLT

LenovoLegionToolkitSetup.zip

Let me know if the issue goes away with this flag set.

Dampfinchen commented 1 year ago

Here is a test build where you can disable the custom tray icon tooltip, since it's not a very common bug, here is how to disable it:

  1. Go to %LOCALAPPDATA%\LenovoLegionToolkit
  2. Create args.txt file in there (if you already have it edit)
  3. Paste --disable-tray-tooltip (if you have other parameters, there should be 1 per line)
  4. Start LLT

LenovoLegionToolkitSetup.zip

Let me know if the issue goes away with this flag set.

Looking good so far.

Savillion commented 1 year ago

I get this error when I block internet connection to llt via simplewall. Maybe it has something to do with driver update section?

BartoszCichecki commented 11 months ago

I am coming back to this error every now and then in an attempt to fix it. If anyone experiences this error regularly and wants to test something that may or may not help here is a test build:

LenovoLegionToolkitSetup.zip

Remember to remove the argument (see above) if you added it.

klour commented 11 months ago

Joining this thread, since I have the same issue from time to time (rarely, without recognising a pattern):

I will try your provided build and see if the issue occurs. Will let you know my observations.

amzon-ex commented 11 months ago

Hi! I've been using LLT for a couple of days now and quite like the idea!

However, I also ran into my first crash yesterday. It seems similar to this one. I retrieved the log from Event Viewer and I'm posting it here if it helps. The source is .NET Runtime. Once Runtime throws the error, LLT crashes.

Log Name:      Application
Source:        .NET Runtime
Date:          22-07-2023 12:20:11 AM
Event ID:      1026
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      minami
Description:
Application: Lenovo Legion Toolkit.exe
CoreCLR Version: 6.0.1623.17311
.NET Version: 6.0.16
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Windows.Controls.Primitives.Popup.OnWindowResize(Object sender, AutoResizedEventArgs e)
   at System.Windows.Interop.HwndSource.Resize(Size newSize)
   at System.Windows.Interop.HwndSource.OnLayoutUpdated(Object obj, EventArgs args)
   at System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()
   at System.Windows.ContextLayoutManager.UpdateLayout()
   at System.Windows.UIElement.UpdateLayout()
   at System.Windows.Interop.HwndSource.SetLayoutSize()
   at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
   at System.Windows.Interop.HwndSource.set_RootVisual(Visual value)
   at System.Windows.Controls.Primitives.Popup.SetRootVisualToPopupRoot()
   at System.Windows.Controls.Primitives.Popup.CreateWindow(Boolean asyncCall)
   at System.Windows.Controls.Primitives.Popup.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
   at System.Windows.Controls.Primitives.Popup.CreateRootPopupInternal(Popup popup, UIElement child, Boolean bindTreatMousePlacementAsBottomProperty)
   at System.Windows.Controls.ContextMenu.HookupParentPopup()
   at System.Windows.Controls.ContextMenu.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at System.Windows.Controls.ContextMenu.set_IsOpen(Boolean value)
   at Hardcodet.Wpf.TaskbarNotification.TaskbarIcon.ShowContextMenu(Point cursorPosition) in D:\a\1\s\src\NotifyIconWpf\TaskbarIcon.cs:line 746
   at Hardcodet.Wpf.TaskbarNotification.TaskbarIcon.OnMouseEvent(MouseEvent me) in D:\a\1\s\src\NotifyIconWpf\TaskbarIcon.cs:line 465
   at Hardcodet.Wpf.TaskbarNotification.Interop.WindowMessageSink.ProcessWindowMessage(UInt32 msg, IntPtr wParam, IntPtr lParam) in D:\a\1\s\src\NotifyIconWpf\Interop\WindowMessageSink.cs:line 275
   at Hardcodet.Wpf.TaskbarNotification.Interop.WindowMessageSink.OnWindowMessageReceived(IntPtr hWnd, UInt32 messageId, IntPtr wParam, IntPtr lParam) in D:\a\1\s\src\NotifyIconWpf\Interop\WindowMessageSink.cs:line 209

Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name=".NET Runtime" />
    <EventID Qualifiers="0">1026</EventID>
    <Version>0</Version>
    <Level>2</Level>
    <Task>0</Task>
    <Opcode>0</Opcode>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2023-07-21T18:50:11.2922873Z" />
    <EventRecordID>696</EventRecordID>
    <Correlation />
    <Execution ProcessID="2964" ThreadID="0" />
    <Channel>Application</Channel>
    <Computer>minami</Computer>
    <Security />
  </System>
  <EventData>
    <Data>Application: Lenovo Legion Toolkit.exe
CoreCLR Version: 6.0.1623.17311
.NET Version: 6.0.16
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Windows.Controls.Primitives.Popup.OnWindowResize(Object sender, AutoResizedEventArgs e)
   at System.Windows.Interop.HwndSource.Resize(Size newSize)
   at System.Windows.Interop.HwndSource.OnLayoutUpdated(Object obj, EventArgs args)
   at System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()
   at System.Windows.ContextLayoutManager.UpdateLayout()
   at System.Windows.UIElement.UpdateLayout()
   at System.Windows.Interop.HwndSource.SetLayoutSize()
   at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
   at System.Windows.Interop.HwndSource.set_RootVisual(Visual value)
   at System.Windows.Controls.Primitives.Popup.SetRootVisualToPopupRoot()
   at System.Windows.Controls.Primitives.Popup.CreateWindow(Boolean asyncCall)
   at System.Windows.Controls.Primitives.Popup.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry&amp; newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
   at System.Windows.Controls.Primitives.Popup.CreateRootPopupInternal(Popup popup, UIElement child, Boolean bindTreatMousePlacementAsBottomProperty)
   at System.Windows.Controls.ContextMenu.HookupParentPopup()
   at System.Windows.Controls.ContextMenu.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry&amp; newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at System.Windows.Controls.ContextMenu.set_IsOpen(Boolean value)
   at Hardcodet.Wpf.TaskbarNotification.TaskbarIcon.ShowContextMenu(Point cursorPosition) in D:\a\1\s\src\NotifyIconWpf\TaskbarIcon.cs:line 746
   at Hardcodet.Wpf.TaskbarNotification.TaskbarIcon.OnMouseEvent(MouseEvent me) in D:\a\1\s\src\NotifyIconWpf\TaskbarIcon.cs:line 465
   at Hardcodet.Wpf.TaskbarNotification.Interop.WindowMessageSink.ProcessWindowMessage(UInt32 msg, IntPtr wParam, IntPtr lParam) in D:\a\1\s\src\NotifyIconWpf\Interop\WindowMessageSink.cs:line 275
   at Hardcodet.Wpf.TaskbarNotification.Interop.WindowMessageSink.OnWindowMessageReceived(IntPtr hWnd, UInt32 messageId, IntPtr wParam, IntPtr lParam) in D:\a\1\s\src\NotifyIconWpf\Interop\WindowMessageSink.cs:line 209
</Data>
  </EventData>
</Event>

This happened when I was suddenly unable to change keyboard backlight and wanted to check if LLT is working. The tooltip didn't pop up (only the blank default tooltip showed). When I tried clicking on it to open LLT, it didn't work. After trying to open LLT using app shortcut, it crashed.

Dampfinchen commented 11 months ago

Maybe it would be a good idea to add a toggle in future releases, as more people have this issue.

BartoszCichecki commented 11 months ago

@amzon-ex try the build linked above, see if it helps.

@Dampfinchen there is an option to workaround this problem in this thread. Also please try the build I posted above.

amzon-ex commented 11 months ago

@BartoszCichecki Thanks for pointing me to it. Giving you feedback on this is problematic, since I haven't encountered the problem since and I'm not sure how to reproduce it. I'll try out the new build anyway, but I might not be able to perceive changes.

klour commented 11 months ago

I started to test/try your new 2.16.0 Beta 1, including your refactored tray icon part. image

Will let you know in your Discord thread about positive/negative experiences.

Dampfinchen commented 11 months ago

@amzon-ex try the build linked above, see if it helps.

@Dampfinchen there is an option to workaround this problem in this thread. Also please try the build I posted above.

I will now test this build and let you know if it fixes the issue!

Dampfinchen commented 11 months ago

@BartoszCichecki I'm pretty confident the issue has been fixed, I've not had it once in the last week. Good job! If others report similar feedback I could close the issue, but we could also leave it open in case the bug reappears someday (unlikely though)

BartoszCichecki commented 10 months ago

Version 2.16.0 was released that contains a complete re-write of tray handling which according to beta testers fixed the issue.

Closing this one for now, but if you encounter crashes in 2.16.0 let me know.