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

Fix: A workaround to avoid AccessViolationException #12089

Merged
merged 1 commit into from
Apr 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/Files.App/Shell/ContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ private void EnumMenuItems(
{
Debug.WriteLine("Item {0} ({1}): {2}", ii, mii.wID, mii.dwTypeData);

// Hackish workaround to avoid an AccessViolationException on some items,
// notably the "Run with graphic processor" menu item of NVidia cards
if (mii.wID - 1 > 5000)
{
container.Dispose();

continue;
}

menuItem.Label = mii.dwTypeData;
menuItem.CommandString = GetCommandString(cMenu, mii.wID - 1);

Expand Down Expand Up @@ -313,11 +322,6 @@ public async Task<bool> LoadSubMenu(List<Win32ContextMenuItem> subItems)

private static string? GetCommandString(Shell32.IContextMenu cMenu, uint offset, Shell32.GCS flags = Shell32.GCS.GCS_VERBW)
{
// Hackish workaround to avoid an AccessViolationException on some items,
// notably the "Run with graphic processor" menu item of NVidia cards
if (offset > 5000)
return null;

SafeCoTaskMemString? commandString = null;

try
Expand Down