microsoft / PowerToys

Windows system utilities to maximize productivity
MIT License
110.62k stars 6.52k forks source link

[PTRun][WindowWalker] Fails for computers where no Virtual Desktops have been created. #16896

Closed jaimecbernardo closed 2 years ago

jaimecbernardo commented 2 years ago

Microsoft PowerToys version

0.57.0-pre

Running as admin

Area(s) with issue?

PowerToys Run

Steps to reproduce

Start PowerToys Run in computers where no Virtual Desktops have been created yet, there's no registry key for the Virtual Desktops. Window Walker is running into an error and not starting in these cases. This is the current state building from main, likely after https://github.com/microsoft/PowerToys/pull/16325

In order to simulate a PC that has never created Virtual desktops, remove these keys from the registry:

✔️ Expected Behavior

PowerToys Run starts normally.

❌ Actual Behavior

This message is shown:

image

This gets added to the PowerToys Run logs.

[2022-03-08 19:53:32.5499] [ERROR] [C:\a\_work\1\s\src\modules\launcher\Wox.Plugin\Common\VirtualDesktop\VirtualDesktopHelper.cs::104]
Failed to read the list of existing desktops form registry.

[2022-03-08 19:53:32.5712] [ERROR] [C:\a\_work\1\s\src\modules\launcher\Wox.Plugin\PluginPair.cs::177]
-------------------------- Begin exception --------------------------
Message: Can't create instance for <Window Walker> in C:\Program Files\PowerToys\modules\launcher\Plugins\WindowWalker\Microsoft.Plugin.WindowWalker.dll

Exception full name  : System.Reflection.TargetInvocationException
Exception message    : Exception has been thrown by the target of an invocation.
Exception stack trace:
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type)
   at Wox.Plugin.PluginPair.CreatePluginInstance()
Exception source     : System.Private.CoreLib
Exception target site: System.Object CreateInstanceDefaultCtor(Boolean, Boolean)
Exception HResult    : -2146232828

Exception full name  : System.TypeInitializationException
Exception message    : The type initializer for 'Microsoft.Plugin.WindowWalker.Main' threw an exception.
Exception stack trace:
   at Microsoft.Plugin.WindowWalker.Main..ctor()
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
Exception source     : Microsoft.Plugin.WindowWalker
Exception target site: Void .ctor()
Exception HResult    : -2146233036

Exception full name  : System.ArgumentOutOfRangeException
Exception message    : Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
Exception stack trace:
   at Wox.Plugin.Common.VirtualDesktop.Helper.VirtualDesktopHelper.UpdateDesktopList()
   at Wox.Plugin.Common.VirtualDesktop.Helper.VirtualDesktopHelper..ctor(Boolean desktopListUpdate)
   at Microsoft.Plugin.WindowWalker.Main..cctor()
Exception source     : System.Private.CoreLib
Exception target site: Void ThrowArgumentOutOfRange_IndexException()
Exception HResult    : -2146233086
-------------------------- End exception --------------------------

Other Software

No response

jaimecbernardo commented 2 years ago

@htcfreek , looks like we missed testing in some conditions ;)

htcfreek commented 2 years ago

Good catch.

I am confused. Is this a special system or did you disabled Virtual Desktops? Based on my testing at least one desktop must exist.

Will look into this tomorrow. Please assign me.

htcfreek commented 2 years ago

@jaimecbernardo Can you please upload me the content of the registry values (especially VirtualDesktopIDs) on the machine?

Was this crash happening after or before showing the PT Run window?

jaimecbernardo commented 2 years ago

Thanks for picking it up. It's a Windows 10 VM where no new Virtual Desktop has been created yet. Those machines don't have those keys in registry.

In order to simulate a PC that has never created Virtual desktops, remove these keys from the registry:

jaimecbernardo commented 2 years ago

It's happening before showing the PT Run window. It's when trying to load the plugins, I think.

htcfreek commented 2 years ago

The question is what we return if this happens. "No desktop exist" or "desktop one" for each window? 🤔

jaimecbernardo commented 2 years ago

The question is what we return if this happens. "No desktop exist" or "desktop one" for each window? 🤔

Perhaps empty string for this case.

htcfreek commented 2 years ago

The question is what we return if this happens. "No desktop exist" or "desktop one" for each window? 🤔

Perhaps empty string for this case.

Yes. This was an idea. It crashes when splitting the binary array from registry because the index that we calculate is invalid. So the idea is to set the desktop list to an empty one.

htcfreek commented 2 years ago

@jaimecbernardo Are you sure that the value VirtualDesktopIDs in \HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\VirtualDesktops really doesn't exist? On my system the explorer crashes if I click on the desktop switcher symbol in task bar and the value is missing.

Or did you disabled virtual desktops with a gpo or something?

jaimecbernardo commented 2 years ago

Perhaps Windows 11 works differently than Windows 10. This is Windows 10. image

htcfreek commented 2 years ago

Perhaps Windows 11 works differently than Windows 10. This is Windows 10. image

I am on windows 10 too. Can you try what happens when you click on this bottun in your task bar: image

htcfreek commented 2 years ago

Perhaps Windows 11 works differently than Windows 10. This is Windows 10. image

I am on windows 10 too. Can you try what happens when you click on this bottun in your task bar: image

The crash on my system must be a race condition when clicking to fast and often on the button.

If I understand you correct, you don't use virtual desktops? So there isn't a condition where the key is missing unexpectedly?

htcfreek commented 2 years ago

found a bug on win 11 too: The current desktopkey has moved: image

jaimecbernardo commented 2 years ago

If I understand you correct, you don't use virtual desktops? So there isn't a condition where the key is missing unexpectedly?

This VM never used Virtual Desktops, so it's expected that the key is missing.

htcfreek commented 2 years ago

If I understand you correct, you don't use virtual desktops? So there isn't a condition where the key is missing unexpectedly?

This VM never used Virtual Desktops, so it's expected that the key is missing.

I have fond the crash reason and the fix is nearly ready. It crashes when trying to selecting desktop one from the empty desktop list. 😅 I will request your review in the PR.

jaimecbernardo commented 2 years ago

Sent a debug build that contained this 😅
The user configuration also ran into it. https://github.com/microsoft/PowerToys/issues/16912#issuecomment-1063993782

htcfreek commented 2 years ago

This is fixed with 0.57.0. Please head over to https://aka.ms/installpowertoys