Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,29 @@

public static void ReleaseHandlerFactories()
{
foreach (var factory in HandlerFactories.Values)
// Snapshot and clear the dictionary up front so that a subsequent call
// or a concurrent LoadPreviewAsync can't pick up a stale RCW we are

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error

RCW is not a recognized word
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
// about to release. This also makes the method idempotent: a second
// call won't try to FinalRelease the same already-separated RCWs.

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error

RCWs is not a recognized word
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
var factories = HandlerFactories.ToArray();
HandlerFactories.Clear();

foreach (var kvp in factories)
{
// Mirror the LockServer(true) we did when caching, so the local
// server can shut down cleanly. Both calls are wrapped because the
// RCW may already be unreachable during process teardown.

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error

RCW is not a recognized word
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
try
{
Marshal.FinalReleaseComObject(factory);
kvp.Value.LockServer(false);
}
catch
{
}

try
{
Marshal.FinalReleaseComObject(kvp.Value);
}
catch
{
Expand Down
19 changes: 16 additions & 3 deletions src/modules/peek/Peek.UI/PeekXAML/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,22 @@
/// <param name="args">AppWindowClosingEventArgs</param>
private void AppWindow_Closing(AppWindow sender, AppWindowClosingEventArgs args)
{
args.Cancel = true;
PowerToysTelemetry.Log.WriteEvent(new ClosedEvent());
Uninitialize();
// Any exception that escapes a WinRT event handler is projected back to
// the CsWinRT dispatcher as a failed HRESULT, and CFlat fail-fasts the
// process. We want a Closing handler that can never crash Peek, even if
// a callee (e.g., a cached preview-handler RCW that has been separated

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error

RCW is not a recognized word
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
// during teardown) throws InvalidComObjectException.
try
{
args.Cancel = true;
PowerToysTelemetry.Log.WriteEvent(new ClosedEvent());
Uninitialize();
}
catch (Exception ex)
{
Logger.LogError("Unhandled exception in Peek MainWindow.AppWindow_Closing; suppressing to avoid fail-fast.", ex);
args.Cancel = true;
}
}

private bool IsNewSingleSelectedItem(SelectedItem selectedItem)
Expand Down
27 changes: 23 additions & 4 deletions src/modules/registrypreview/RegistryPreview/MainWindow.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

using Microsoft.UI.Xaml;
using Windows.Data.Json;
using WinUIEx;
Expand All @@ -15,10 +17,27 @@
/// </summary>
private void AppWindow_Closing(Microsoft.UI.Windowing.AppWindow sender, Microsoft.UI.Windowing.AppWindowClosingEventArgs args)
{
jsonWindowPlacement.SetNamedValue("appWindow.Position.X", JsonValue.CreateNumberValue(AppWindow.Position.X));
jsonWindowPlacement.SetNamedValue("appWindow.Position.Y", JsonValue.CreateNumberValue(AppWindow.Position.Y));
jsonWindowPlacement.SetNamedValue("appWindow.Size.Width", JsonValue.CreateNumberValue(AppWindow.Size.Width));
jsonWindowPlacement.SetNamedValue("appWindow.Size.Height", JsonValue.CreateNumberValue(AppWindow.Size.Height));
// Any exception that escapes a WinRT event handler is projected back to
// the CsWinRT dispatcher as a failed HRESULT, and CFlat fail-fasts the
// process. Defend the handler so a transient teardown failure (e.g.,
// null placement state, separated RCW during shutdown) can't terminate

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error

RCW is not a recognized word
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
// the editor unexpectedly.
try
{
if (jsonWindowPlacement == null)
{
return;
}

jsonWindowPlacement.SetNamedValue("appWindow.Position.X", JsonValue.CreateNumberValue(AppWindow.Position.X));
jsonWindowPlacement.SetNamedValue("appWindow.Position.Y", JsonValue.CreateNumberValue(AppWindow.Position.Y));
jsonWindowPlacement.SetNamedValue("appWindow.Size.Width", JsonValue.CreateNumberValue(AppWindow.Size.Width));
jsonWindowPlacement.SetNamedValue("appWindow.Size.Height", JsonValue.CreateNumberValue(AppWindow.Size.Height));
}
catch (Exception ex)
{
ManagedCommon.Logger.LogError("Unhandled exception in RegistryPreview MainWindow.AppWindow_Closing; suppressing to avoid fail-fast.", ex);
}
}

/// <summary>
Expand Down
Loading