Skip to content

Commit 1e70e18

Browse files
lheckerDHowett
authored andcommitted
Prevent RPC_E_CANTCALLOUT_ININPUTSYNCCALL during WM_SETTINGCHANGE (#19755)
Closes #19505 (cherry picked from commit e8971c8) Service-Card-Id: PVTI_lADOAF3p4s4BBcTlzgkC_Mg Service-Version: 1.24
1 parent 48e2d93 commit 1e70e18

5 files changed

Lines changed: 20 additions & 4 deletions

File tree

.github/actions/spelling/expect/expect.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ BValue
141141
Cacafire
142142
CALLCONV
143143
CANDRABINDU
144+
CANTCALLOUT
144145
capslock
145146
CARETBLINKINGENABLED
146147
CARRIAGERETURN
@@ -809,6 +810,7 @@ inclusivity
809810
INCONTEXT
810811
INFOEX
811812
inheritcursor
813+
ININPUTSYNCCALL
812814
INITCOMMONCONTROLSEX
813815
INITDIALOG
814816
INITGUID

src/cascadia/TerminalApp/AppLogic.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ namespace winrt::TerminalApp::implementation
150150
});
151151

152152
_languageProfileNotifier = winrt::make_self<LanguageProfileNotifier>([this]() {
153-
_reloadSettings->Run();
153+
// TODO: This is really bad, because we reset any current user customizations.
154+
// See GH#11522.
155+
ReloadSettingsThrottled();
154156
});
155157

156158
// Do this here, rather than at the top of main. This will prevent us from
@@ -330,7 +332,7 @@ namespace winrt::TerminalApp::implementation
330332

331333
if (modifiedBasename == settingsBasename)
332334
{
333-
_reloadSettings->Run();
335+
ReloadSettingsThrottled();
334336
}
335337
});
336338
}
@@ -436,6 +438,11 @@ namespace winrt::TerminalApp::implementation
436438
SettingsChanged.raise(*this, *ev);
437439
}
438440

441+
void AppLogic::ReloadSettingsThrottled()
442+
{
443+
_reloadSettings->Run();
444+
}
445+
439446
// This is a continuation of AppLogic::Create() and includes the more expensive parts.
440447
void AppLogic::NotifyRootInitialized()
441448
{

src/cascadia/TerminalApp/AppLogic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace winrt::TerminalApp::implementation
3636
bool IsRunningElevated() const noexcept;
3737
bool CanDragDrop() const noexcept;
3838
void ReloadSettings();
39+
void ReloadSettingsThrottled();
3940
void NotifyRootInitialized();
4041

4142
bool HasSettingsStartupActions() const noexcept;
@@ -80,7 +81,6 @@ namespace winrt::TerminalApp::implementation
8081
[[nodiscard]] HRESULT _TryLoadSettings() noexcept;
8182
void _ProcessLazySettingsChanges();
8283
void _RegisterSettingsChange();
83-
safe_void_coroutine _DispatchReloadSettings();
8484

8585
void _setupFolderPathEnvVar();
8686

src/cascadia/TerminalApp/AppLogic.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace TerminalApp
2525
Boolean HasSettingsStartupActions();
2626

2727
void ReloadSettings();
28+
void ReloadSettingsThrottled();
2829
Microsoft.Terminal.Settings.Model.CascadiaSettings Settings { get; };
2930

3031
TerminalWindow CreateNewWindow();

src/cascadia/WindowsTerminal/WindowEmperor.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,13 @@ LRESULT WindowEmperor::_messageHandler(HWND window, UINT const message, WPARAM c
993993
if (isCurrentlyDark != _currentSystemThemeIsDark)
994994
{
995995
_currentSystemThemeIsDark = isCurrentlyDark;
996-
_app.Logic().ReloadSettings();
996+
997+
// GH#19505: WM_SETTINGCHANGE gets sent out with a SendMessage() call, which means
998+
// that COM methods marked as [input_sync] cannot be called. Well, our CascadiaSettings
999+
// loader does call such methods. This results in RPC_E_CANTCALLOUT_ININPUTSYNCCALL, aka:
1000+
// "An outgoing call cannot be made since the application is dispatching an input-synchronous call."
1001+
// The solution is to simply do it in another tick.
1002+
_app.Logic().ReloadSettingsThrottled();
9971003
}
9981004
}
9991005
return 0;

0 commit comments

Comments
 (0)