From 68c199aa64873c51fd43d1799889020cd0b1d103 Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Wed, 6 Oct 2021 15:54:15 +0100 Subject: [PATCH] [KBM Editor] Catch UpdateLayout exceptions (#13635) --- .../EditKeyboardWindow.cpp | 9 ++++- .../EditShortcutsWindow.cpp | 9 ++++- .../KeyboardManagerState.cpp | 27 ++++++++++++-- .../ShortcutControl.cpp | 18 ++++++++-- .../SingleKeyRemapControl.cpp | 36 ++++++++++++++++--- 5 files changed, 88 insertions(+), 11 deletions(-) diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditKeyboardWindow.cpp b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditKeyboardWindow.cpp index bd86772840..069e0ac89b 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditKeyboardWindow.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditKeyboardWindow.cpp @@ -354,7 +354,14 @@ inline void CreateEditKeyboardWindowImpl(HINSTANCE hInst, KBMEditor::KeyboardMan xamlContainer.Children().Append(header); xamlContainer.Children().Append(helperText); xamlContainer.Children().Append(scrollViewer); - xamlContainer.UpdateLayout(); + try + { + // If a layout update has been triggered by other methods (e.g.: adapting to zoom level), this may throw an exception. + xamlContainer.UpdateLayout(); + } + catch (...) + { + } desktopSource.Content(xamlContainer); ////End XAML Island section diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditShortcutsWindow.cpp b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditShortcutsWindow.cpp index 464327b702..716b398177 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditShortcutsWindow.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/EditShortcutsWindow.cpp @@ -325,7 +325,14 @@ inline void CreateEditShortcutsWindowImpl(HINSTANCE hInst, KBMEditor::KeyboardMa xamlContainer.Children().Append(header); xamlContainer.Children().Append(helperText); xamlContainer.Children().Append(scrollViewer); - xamlContainer.UpdateLayout(); + try + { + // If a layout update has been triggered by other methods (e.g.: adapting to zoom level), this may throw an exception. + xamlContainer.UpdateLayout(); + } + catch (...) + { + } desktopSource.Content(xamlContainer); diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/KeyboardManagerState.cpp b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/KeyboardManagerState.cpp index 037fa2edf8..c3a92f4e94 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/KeyboardManagerState.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/KeyboardManagerState.cpp @@ -171,8 +171,22 @@ void KeyboardManagerState::UpdateDetectShortcutUI() AddKeyToLayout(currentShortcutUI2.as(), shortcut[i]); } } - currentShortcutUI1.as().UpdateLayout(); - currentShortcutUI2.as().UpdateLayout(); + try + { + // If a layout update has been triggered by other methods (e.g.: adapting to zoom level), this may throw an exception. + currentShortcutUI1.as().UpdateLayout(); + } + catch (...) + { + } + try + { + // If a layout update has been triggered by other methods (e.g.: adapting to zoom level), this may throw an exception. + currentShortcutUI2.as().UpdateLayout(); + } + catch (...) + { + } }); } @@ -189,7 +203,14 @@ void KeyboardManagerState::UpdateDetectSingleKeyRemapUI() currentSingleKeyUI.as().Children().Clear(); hstring key = winrt::to_hstring(keyboardMap.GetKeyName(detectedRemapKey).c_str()); AddKeyToLayout(currentSingleKeyUI.as(), key); - currentSingleKeyUI.as().UpdateLayout(); + try + { + // If a layout update has been triggered by other methods (e.g.: adapting to zoom level), this may throw an exception. + currentSingleKeyUI.as().UpdateLayout(); + } + catch (...) + { + } }); } diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp index ef502d9671..ac57a8967c 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEditorLibrary/ShortcutControl.cpp @@ -42,7 +42,14 @@ ShortcutControl::ShortcutControl(StackPanel table, StackPanel row, const int col shortcutControlLayout.as().Children().Append(typeShortcut.as