Skip to content

Commit 1149f0a

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_lADOAF3p4s4AxadtzgkC_Mk Service-Version: 1.23
1 parent a0724f9 commit 1149f0a

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ cac
153153
cacafire
154154
CALLCONV
155155
CANDRABINDU
156+
CANTCALLOUT
156157
capslock
157158
CARETBLINKINGENABLED
158159
CARRIAGERETURN
@@ -858,6 +859,7 @@ inclusivity
858859
INCONTEXT
859860
INFOEX
860861
inheritcursor
862+
ININPUTSYNCCALL
861863
INITCOMMONCONTROLSEX
862864
INITDIALOG
863865
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
@@ -991,7 +991,13 @@ LRESULT WindowEmperor::_messageHandler(HWND window, UINT const message, WPARAM c
991991
if (isCurrentlyDark != _currentSystemThemeIsDark)
992992
{
993993
_currentSystemThemeIsDark = isCurrentlyDark;
994-
_app.Logic().ReloadSettings();
994+
995+
// GH#19505: WM_SETTINGCHANGE gets sent out with a SendMessage() call, which means
996+
// that COM methods marked as [input_sync] cannot be called. Well, our CascadiaSettings
997+
// loader does call such methods. This results in RPC_E_CANTCALLOUT_ININPUTSYNCCALL, aka:
998+
// "An outgoing call cannot be made since the application is dispatching an input-synchronous call."
999+
// The solution is to simply do it in another tick.
1000+
_app.Logic().ReloadSettingsThrottled();
9951001
}
9961002
}
9971003
return 0;

0 commit comments

Comments
 (0)