Skip to content

Commit 4621507

Browse files
HariniMalothu17Harini Malothu
andauthored
[0.81]Fix crash in ABIViewManager::RemoveAllChildren during shutdown (#15633)
* Fix crash in ABIViewManager::RemoveAllChildren during shutdown * Change files --------- Co-authored-by: Harini Malothu <hmalothu@microsoft.com>
1 parent abadef8 commit 4621507

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "none",
3+
"comment": "Fix crash in ABIViewManager::RemoveAllChildren during shutdown",
4+
"packageName": "react-native-windows",
5+
"email": "hmalothu@microsoft.com",
6+
"dependentChangeType": "none"
7+
}

vnext/Microsoft.ReactNative/ABIViewManager.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,19 @@ void ABIViewManager::AddView(const xaml::DependencyObject &parent, const xaml::D
190190
}
191191

192192
void ABIViewManager::RemoveAllChildren(const xaml::DependencyObject &parent) {
193+
if (!parent) {
194+
return;
195+
}
196+
193197
if (m_viewManagerWithChildren) {
194-
m_viewManagerWithChildren.RemoveAllChildren(parent.as<xaml::FrameworkElement>());
198+
auto fe = parent.try_as<xaml::FrameworkElement>();
199+
if (fe) {
200+
try {
201+
m_viewManagerWithChildren.RemoveAllChildren(fe);
202+
} catch (...) {
203+
// External view manager may fail during shutdown if view is already disposed
204+
}
205+
}
195206
} else {
196207
Super::RemoveAllChildren(parent);
197208
}

0 commit comments

Comments
 (0)