Slion / VirtualDesktop

C# wrapper for the Virtual Desktop API on Windows 11.
MIT License
21 stars 9 forks source link

Fix crash on desktop switch #18

Closed AkazaRenn closed 10 months ago

AkazaRenn commented 11 months ago

https://github.com/Slion/VirtualDesktop/issues/15

Referred to the implementation here: https://github.com/hwtnb/VirtualDesktop/blob/102f693f3a076189ca8c25f33cd9918c96365af5/source/VirtualDesktop/Interop/(interfaces)/22621/IVirtualDesktopNotification.cs#L85

Seems like what failed is not ViewVirtualDesktopChanged but the new VirtualDesktopSwitched, which is also fired when we are switching desktops. Not sure why we have two of them... But anyways, made implementation for it and seems fine now.

AkazaRenn commented 11 months ago

Actually if this line wasn't added, it should not fail. Seems like the problem is on a dead recursion that it keeps invoking itself, Visual Studio is definitely to be blamed for not calling it out.

Dexterously commented 11 months ago

image

Got these errors... Once I fixed them it worked like a charm!

AkazaRenn commented 11 months ago

image

Got these errors... Once I fixed them it worked like a charm!

Sorry I'm not sure why they would happen, do you mind sharing your diff so I can include it here?

Slion commented 10 months ago

Looks awesome, thanks for looking into this. I wonder when were those signatures changed though. Your suggested change just changes the 2215 interface but we know it was working fine in 2215. Surely we ought to deploy a new variant of the APIs instead. Question is when did the problem start? For me is was only an issue from 2506 put for others is was from 2361 as suggested in #15.

AkazaRenn commented 10 months ago

@Slion I don't know much about signature but my assumption is that it had never worked. It didn't break in the old version of Windows because those interfaces were defined but never used, until 23H2 and they started causing problems. You could check the other fork I provided in the PR description for a reference.

AkazaRenn commented 10 months ago

@Slion You did some non-ending recursive calls:

public IVirtualDesktop VirtualDesktopSwitched() 
{ 
// Calling itself 
    return this.VirtualDesktopSwitched(); 
} 

public IVirtualDesktop RemoteVirtualDesktopConnected() 
{ 
// Calling itself 
    return this.RemoteVirtualDesktopConnected(); 
}
Slion commented 10 months ago

I don't know much about signature but my assumption is that it had never worked. It didn't break in the old version of Windows because those interfaces were defined but never used, until 23H2 and they started causing problems

Good point, so you are saying we should just merge it as it is then. That could also explain why some of us saw it starting to fail earlier than others.

You did some non-ending recursive calls

Nasty, but not guilty 😁 I surely did not code that myself, did I?