Skip to content

Commit 26595a4

Browse files
Maybe fix Shell crash on exit on MacCatalyst
Check whether ShellSectionRootRenderer has been disposed before responding to TraitCollectionDidChange to potentially avoid an ObjectDisposedException retrieving the IApplication service. Fixes: #33352
1 parent 235cb6f commit 26595a4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRootRenderer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,14 @@ public override void ViewSafeAreaInsetsDidChange()
143143

144144
public override void TraitCollectionDidChange(UITraitCollection previousTraitCollection)
145145
{
146+
if (_isDisposed)
147+
return;
148+
146149
#pragma warning disable CA1422 // Validate platform compatibility
147150
base.TraitCollectionDidChange(previousTraitCollection);
148151
#pragma warning restore CA1422 // Validate platform compatibility
149152

150-
var application = _shellContext?.Shell?.FindMauiContext().Services.GetService<IApplication>();
153+
var application = _shellContext?.Shell?.FindMauiContext()?.Services.GetService<IApplication>();
151154
application?.ThemeChanged();
152155
}
153156

0 commit comments

Comments
 (0)