Skip to content

Commit 94d60c2

Browse files
committed
Fix a crash calling CallInvoker during shutdown (#16310)
* Fix a crash calling CallInvoker during shutdown * Change files * build fix
1 parent e0836b9 commit 94d60c2

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Fix a crash calling CallInvoker during shutdown",
4+
"packageName": "react-native-windows",
5+
"email": "30809111+acoates-ms@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}

vnext/Microsoft.ReactNative.Cxx/TurboModuleProvider.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,23 @@ struct AbiCallInvoker final : facebook::react::CallInvoker {
1313
AbiCallInvoker(IReactContext const &context) : m_context(context) {}
1414

1515
void invokeAsync(facebook::react::CallFunc &&func) noexcept override {
16-
m_context.CallInvoker().InvokeAsync(
17-
[context = m_context, func = std::move(func)](const winrt::Windows::Foundation::IInspectable &runtimeHandle) {
18-
func(GetOrCreateContextRuntime(context, runtimeHandle));
19-
});
16+
auto callInvoker = m_context.CallInvoker();
17+
if (callInvoker) {
18+
callInvoker.InvokeAsync(
19+
[context = m_context, func = std::move(func)](const winrt::Windows::Foundation::IInspectable &runtimeHandle) {
20+
func(GetOrCreateContextRuntime(context, runtimeHandle));
21+
});
22+
}
2023
}
2124

2225
void invokeSync(facebook::react::CallFunc &&func) override {
23-
m_context.CallInvoker().InvokeSync(
24-
[context = m_context, func = std::move(func)](const winrt::Windows::Foundation::IInspectable &runtimeHandle) {
25-
func(GetOrCreateContextRuntime(context, runtimeHandle));
26-
});
26+
auto callInvoker = m_context.CallInvoker();
27+
if (callInvoker) {
28+
callInvoker.InvokeSync(
29+
[context = m_context, func = std::move(func)](const winrt::Windows::Foundation::IInspectable &runtimeHandle) {
30+
func(GetOrCreateContextRuntime(context, runtimeHandle));
31+
});
32+
}
2733
}
2834

2935
private:

0 commit comments

Comments
 (0)