Fix Glide IllegalArgumentException in MauiCustomTarget.clear() for destroyed activities#29780
Fix Glide IllegalArgumentException in MauiCustomTarget.clear() for destroyed activities#29780PureWeen merged 13 commits intoinflight/currentfrom
Conversation
Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java
Outdated
Show resolved
Hide resolved
src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java
Outdated
Show resolved
Hide resolved
src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/glide/MauiCustomTarget.java
Outdated
Show resolved
Hide resolved
src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/glide/MauiCustomTarget.java
Outdated
Show resolved
Hide resolved
jonathanpeppers
left a comment
There was a problem hiding this comment.
How do we add a test for this issue?
…fy patterns Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
jonathanpeppers
left a comment
There was a problem hiding this comment.
Figure out how we add a test for this issue. We don't want it to regress in the future.
src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java
Outdated
Show resolved
Hide resolved
Testing this requires adding Java unit tests to the AndroidNative module since the fix is in Java code. Here's the approach:
Would you like me to implement these tests? The current fix can be verified manually by simulating app backgrounding/foregrounding scenarios that trigger activity destruction during image loads. |
|
Can we add the tests in C# with existing projects? I'm not sure we want to add a new Java test project. |
…tests Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Added comprehensive unit tests in Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
...droidNative/maui/src/test/java/com/microsoft/maui/PlatformInteropContextDestructionTest.java
Outdated
Show resolved
Hide resolved
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
@jonathanpeppers which trace are you after? there are plenty posted between this PR page and the originating issue page that reference the java code. personally I've not been able to reproduce the original issue (so I can't try any fixes), but we do see it user logs. |
|
It's a long thread, but the one relevant one I see is: We could try the fix in simply |
src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/glide/MauiCustomTarget.java
Outdated
Show resolved
Hide resolved
src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformLogger.java
Outdated
Show resolved
Hide resolved
src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java
Outdated
Show resolved
Hide resolved
src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java
Outdated
Show resolved
Hide resolved
src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java
Outdated
Show resolved
Hide resolved
src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java
Outdated
Show resolved
Hide resolved
src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java
Outdated
Show resolved
Hide resolved
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
jonathanpeppers
left a comment
There was a problem hiding this comment.
This now looks reasonable to fix this:
java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity
at com.bumptech.glide.manager.RequestManagerRetriever.assertNotDestroyed(RequestManagerRetriever.java:236)
at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:110)
at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:92)
at com.bumptech.glide.Glide.with(Glide.java:545)
at com.microsoft.maui.glide.MauiCustomTarget.lambda$clear$0$com-microsoft-maui-glide-MauiCustomTarget(MauiCustomTarget.java:88)
at com.microsoft.maui.glide.MauiCustomTarget$$ExternalSyntheticLambda1.run(D8$$SyntheticClass:0)
at com.microsoft.maui.glide.MauiCustomTarget.post(MauiCustomTarget.java:75)
at com.microsoft.maui.glide.MauiCustomTarget.clear(MauiCustomTarget.java:86)
at com.microsoft.maui.glide.MauiCustomTarget.$r8$lambda$IYvOQogjutk8hNIBw8oqNZ8cxUU(Unknown Source:0)
at com.microsoft.maui.glide.MauiCustomTarget$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
Assuming CI is green, can we put this on the inflight PR? @PureWeen
|
@jonathanpeppers did you read the original bug that is linked to this PR? in there you can see stuff like
this is what I get in my error reports
|
…stroyed activities (#29780) ## Problem Random crashes occurring on Android devices with the error: ``` java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity at com.bumptech.glide.manager.RequestManagerRetriever.assertNotDestroyed(RequestManagerRetriever.java:236) at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:110) at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:92) at com.bumptech.glide.Glide.with(Glide.java:545) at com.microsoft.maui.glide.MauiCustomTarget.lambda$clear$0$com-microsoft-maui-glide-MauiCustomTarget(MauiCustomTarget.java:88) ``` This happens when Glide attempts to clear image targets using a Context whose underlying Activity has been destroyed. ## Solution Added defensive context destruction check in `MauiCustomTarget.clear()` before calling `Glide.with(context).clear(this)`. **Key Changes:** 1. **Added private context lifecycle validation methods to MauiCustomTarget:** - `isContextDestroyed()` - Checks if context/activity is destroyed or finishing - `getActivity()` - Safely extracts Activity from Context (handles ContextWrapper chains) 2. **Protected MauiCustomTarget.clear() operation:** - Added context check before calling `Glide.with(context).clear(this)` - Includes verbose logging when the clear operation is skipped due to destroyed context **Behavior:** - When context is destroyed, `clear()` returns early without attempting to call Glide - Matches Glide's own validation logic: `activity.isFinishing() || activity.isDestroyed()` - Logs a debug message when clear is skipped (if verbose logging is enabled) **Example of the fix:** ```java private void clear() { post(() -> { if (isContextDestroyed(context)) { if (logger.isVerboseLoggable) { logger.v("clear() skipped - context destroyed: " + resourceLogIdentifier); } return; } Glide .with(context) .clear(this); }); } ``` This is a surgical, minimal fix that targets the specific crash location identified in the stack trace while maintaining all existing functionality. Fixes #29699. --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more <a href="https://gh.io/copilot-coding-agent-tips">Copilot coding agent tips</a> in the docs. <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/dotnet/maui/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com> Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
…stroyed activities (#29780) ## Problem Random crashes occurring on Android devices with the error: ``` java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity at com.bumptech.glide.manager.RequestManagerRetriever.assertNotDestroyed(RequestManagerRetriever.java:236) at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:110) at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:92) at com.bumptech.glide.Glide.with(Glide.java:545) at com.microsoft.maui.glide.MauiCustomTarget.lambda$clear$0$com-microsoft-maui-glide-MauiCustomTarget(MauiCustomTarget.java:88) ``` This happens when Glide attempts to clear image targets using a Context whose underlying Activity has been destroyed. ## Solution Added defensive context destruction check in `MauiCustomTarget.clear()` before calling `Glide.with(context).clear(this)`. **Key Changes:** 1. **Added private context lifecycle validation methods to MauiCustomTarget:** - `isContextDestroyed()` - Checks if context/activity is destroyed or finishing - `getActivity()` - Safely extracts Activity from Context (handles ContextWrapper chains) 2. **Protected MauiCustomTarget.clear() operation:** - Added context check before calling `Glide.with(context).clear(this)` - Includes verbose logging when the clear operation is skipped due to destroyed context **Behavior:** - When context is destroyed, `clear()` returns early without attempting to call Glide - Matches Glide's own validation logic: `activity.isFinishing() || activity.isDestroyed()` - Logs a debug message when clear is skipped (if verbose logging is enabled) **Example of the fix:** ```java private void clear() { post(() -> { if (isContextDestroyed(context)) { if (logger.isVerboseLoggable) { logger.v("clear() skipped - context destroyed: " + resourceLogIdentifier); } return; } Glide .with(context) .clear(this); }); } ``` This is a surgical, minimal fix that targets the specific crash location identified in the stack trace while maintaining all existing functionality. Fixes #29699. --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more <a href="https://gh.io/copilot-coding-agent-tips">Copilot coding agent tips</a> in the docs. <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/dotnet/maui/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com> Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
…stroyed activities (#29780) ## Problem Random crashes occurring on Android devices with the error: ``` java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity at com.bumptech.glide.manager.RequestManagerRetriever.assertNotDestroyed(RequestManagerRetriever.java:236) at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:110) at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:92) at com.bumptech.glide.Glide.with(Glide.java:545) at com.microsoft.maui.glide.MauiCustomTarget.lambda$clear$0$com-microsoft-maui-glide-MauiCustomTarget(MauiCustomTarget.java:88) ``` This happens when Glide attempts to clear image targets using a Context whose underlying Activity has been destroyed. ## Solution Added defensive context destruction check in `MauiCustomTarget.clear()` before calling `Glide.with(context).clear(this)`. **Key Changes:** 1. **Added private context lifecycle validation methods to MauiCustomTarget:** - `isContextDestroyed()` - Checks if context/activity is destroyed or finishing - `getActivity()` - Safely extracts Activity from Context (handles ContextWrapper chains) 2. **Protected MauiCustomTarget.clear() operation:** - Added context check before calling `Glide.with(context).clear(this)` - Includes verbose logging when the clear operation is skipped due to destroyed context **Behavior:** - When context is destroyed, `clear()` returns early without attempting to call Glide - Matches Glide's own validation logic: `activity.isFinishing() || activity.isDestroyed()` - Logs a debug message when clear is skipped (if verbose logging is enabled) **Example of the fix:** ```java private void clear() { post(() -> { if (isContextDestroyed(context)) { if (logger.isVerboseLoggable) { logger.v("clear() skipped - context destroyed: " + resourceLogIdentifier); } return; } Glide .with(context) .clear(this); }); } ``` This is a surgical, minimal fix that targets the specific crash location identified in the stack trace while maintaining all existing functionality. Fixes #29699. --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more <a href="https://gh.io/copilot-coding-agent-tips">Copilot coding agent tips</a> in the docs. <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/dotnet/maui/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com> Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
…stroyed activities (#29780) ## Problem Random crashes occurring on Android devices with the error: ``` java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity at com.bumptech.glide.manager.RequestManagerRetriever.assertNotDestroyed(RequestManagerRetriever.java:236) at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:110) at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:92) at com.bumptech.glide.Glide.with(Glide.java:545) at com.microsoft.maui.glide.MauiCustomTarget.lambda$clear$0$com-microsoft-maui-glide-MauiCustomTarget(MauiCustomTarget.java:88) ``` This happens when Glide attempts to clear image targets using a Context whose underlying Activity has been destroyed. ## Solution Added defensive context destruction check in `MauiCustomTarget.clear()` before calling `Glide.with(context).clear(this)`. **Key Changes:** 1. **Added private context lifecycle validation methods to MauiCustomTarget:** - `isContextDestroyed()` - Checks if context/activity is destroyed or finishing - `getActivity()` - Safely extracts Activity from Context (handles ContextWrapper chains) 2. **Protected MauiCustomTarget.clear() operation:** - Added context check before calling `Glide.with(context).clear(this)` - Includes verbose logging when the clear operation is skipped due to destroyed context **Behavior:** - When context is destroyed, `clear()` returns early without attempting to call Glide - Matches Glide's own validation logic: `activity.isFinishing() || activity.isDestroyed()` - Logs a debug message when clear is skipped (if verbose logging is enabled) **Example of the fix:** ```java private void clear() { post(() -> { if (isContextDestroyed(context)) { if (logger.isVerboseLoggable) { logger.v("clear() skipped - context destroyed: " + resourceLogIdentifier); } return; } Glide .with(context) .clear(this); }); } ``` This is a surgical, minimal fix that targets the specific crash location identified in the stack trace while maintaining all existing functionality. Fixes #29699. --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more <a href="https://gh.io/copilot-coding-agent-tips">Copilot coding agent tips</a> in the docs. <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/dotnet/maui/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jfversluis <939291+jfversluis@users.noreply.github.com> Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
## What's Coming .NET MAUI inflight/candidate introduces significant improvements across all platforms with focus on quality, performance, and developer experience. This release includes 16 commits with various improvements, bug fixes, and enhancements. ## Checkbox - [Android] Implement material3 support for CheckBox by @HarishwaranVijayakumar in #33339 <details> <summary>🔧 Fixes</summary> - [Implement Material3 Support for CheckBox](#33338) </details> ## CollectionView - [Android] Fixed EmptyView doesn’t display when CollectionView is placed inside a VerticalStackLayout by @NanthiniMahalingam in #33134 <details> <summary>🔧 Fixes</summary> - [CollectionView does not show an EmptyView template with an empty collection](#32932) </details> ## Essentials - [Windows]Fix NullReferenceException in OpenReadAsync for FileResult created with full path by @devanathan-vaithiyanathan in #28238 <details> <summary>🔧 Fixes</summary> - [[Windows] FileResult(string fullPath) not initialized properly](#26858) </details> ## Image - Fix Glide IllegalArgumentException in MauiCustomTarget.clear() for destroyed activities by @jfversluis via @Copilot in #29780 <details> <summary>🔧 Fixes</summary> - [java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity - glide](#29699) </details> ## Label - [Android] Fix for Label WordWrap width issue causing HorizontalOptions misalignment by @praveenkumarkarunanithi in #33281 <details> <summary>🔧 Fixes</summary> - [[Android] Unexpected Line Breaks in Android, Label with WordWrap Mode Due to Trailing Space.](#31782) - [Label not sized correctly on Android](#27614) </details> - Fix to Improve Flyout Accessibility by Adjusting UITableViewController Labels by @SuthiYuvaraj in #31619 <details> <summary>🔧 Fixes</summary> - [Navigation section present under hamburger are programmatically define as table :A11y_.NET maui_User can get all the insights of Dashboard_Devtools](#30894) </details> ## Mediapicker - [Regression][iOS] Fix MediaPicker PickPhotosAsync getting file name in contentType property by @devanathan-vaithiyanathan in #33390 <details> <summary>🔧 Fixes</summary> - [[iOS] MediaPicker PickPhotosAsync getting file name in contentType property](#33348) </details> ## Navigation - Fix handler not disconnected when removing non visible pages using RemovePage() by @Vignesh-SF3580 in #32289 <details> <summary>🔧 Fixes</summary> - [NavigationPage.Navigation.RemovePage() fails to disconnect handlers when removing pages, unlike ContentPage.Navigation.RemovePage()](#32239) </details> ## Picker - [Android] Fix Picker IsOpen not reset when picker is dismissed by @devanathan-vaithiyanathan in #33332 <details> <summary>🔧 Fixes</summary> - [[Android] Picker IsOpen not reset when picker is dismissed](#33331) </details> ## Shell - [iOS & Catalyst ] Fixed IsEnabled property should work on Tabs by @SubhikshaSf4851 in #33369 <details> <summary>🔧 Fixes</summary> - [[Catalyst] TabBarBackgroundColor, TabBarUnselectedColor, and IsEnabled Not Working as Expected in Shell](#33158) </details> - [iOS,Windows] Fix navigation bar colors not resetting when switching ShellContent by @Vignesh-SF3580 in #33228 <details> <summary>🔧 Fixes</summary> - [[iOS, Windows] Shell Navigation bar colors are not updated correctly when switching ShellContent](#33227) </details> - [iOS] Fixed Shell navigation on search handler suggestion selection by @SubhikshaSf4851 in #33406 <details> <summary>🔧 Fixes</summary> - [[iOS] Clicking on search suggestions fails to navigate to detail page correctly](#33356) </details> ## Templates - Fix VoiceOver doesnot announces the State of the ComboBox by @SuthiYuvaraj in #32286 ## Xaml - [XSG][BindingSourceGen] Add support for CommunityToolkit.Mvvm ObservablePropertyAttribute by @simonrozsival via @Copilot in #33028 <details> <summary>🔧 Fixes</summary> - [[XSG] Add heuristic to support bindable properties generated by other source generators](#32597) </details> <details> <summary>📦 Other (2)</summary> - [XSG] Improve diagnostic reporting during binding compilation by @simonrozsival via @Copilot in #32905 - [Testing] Fixed Test case failure in PR 33574 - [01/19/2026] Candidate - 1 by @TamilarasanSF4853 in #33602 </details> **Full Changelog**: main...inflight/candidate
…ctivities (#33805) - [x] Analyze the issue and understand the crash from stack trace - [x] Review PR #29780 fix pattern for destroyed activity context check - [x] Add context destruction check in `PlatformInterop.loadImageFromFont(Context...)` method - [x] Add context destruction check in other `PlatformInterop` methods that use `Glide.with(context)`: - [x] `loadImageFromFile(Context...)` - [x] `loadImageFromUri(Context...)` - [x] `loadImageFromStream(Context...)` - [x] Verify changes compile successfully - [x] Move `isContextDestroyed` and `getActivity` methods to `PlatformInterop` and have `MauiCustomTarget` call them - [x] Run code review - [x] Run CodeQL security scan - [x] Final verification <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> ---- *This section details on the original issue you should resolve* <issue_title>java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity - glide</issue_title> <issue_description>### Description Random issue that I can not reproduce but happening on a small subset of devices according to firebase I believe a previously closed issue maybe the same thing happening: #17549 ### Steps to Reproduce No enough information to say at this point. ### Link to public reproduction project repository _No response_ ### Version with bug 9.0.70 SR7 ### Is this a regression from previous behavior? Yes, this used to work in .NET MAUI ### Last version that worked well 7.0.92 ### Affected platforms Android ### Affected platform versions Android 14 and up ### Did you find any workaround? No ### Relevant log output ```shell Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{######/crc641b109f8ad35faaaf.MainActivity}: java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4206) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4393) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222) at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133) at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773) at android.os.Handler.dispatchMessage(Handler.java:109) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.app.ActivityThread.main(ActivityThread.java:8934) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911) Caused by java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity at com.bumptech.glide.manager.RequestManagerRetriever.assertNotDestroyed(RequestManagerRetriever.java:236) at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:110) at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:92) at com.bumptech.glide.Glide.with(Glide.java:545) at com.microsoft.maui.PlatformInterop.loadImageFromFont(PlatformInterop.java:394) at crc641b109f8ad35faaaf.MainActivity.n_onCreate(MainActivity.java) at crc641b109f8ad35faaaf.MainActivity.onCreate(MainActivity.java:63) at android.app.Activity.performCreate(Activity.java:9079) at android.app.Activity.performCreate(Activity.java:9057) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1531) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4188) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4393) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222) at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133) at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773) at android.os.Handler.dispatchMessage(Handler.java:109) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.app.ActivityThread.main(ActivityThread.java:8934) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911) ```</issue_description> <agent_instructions>Looking at the stack trace above, it looks like the problem started in `loadImageFromFont()`. This PR: * #29780 Fixes the `clear()` code path, can we apply this to the stack trace on this issue?</agent_instructions> ## Comments on the Issue (you are @copilot in this section) <comments> <comment_new><author>@NafeelaNazhir</author><body> This issue has been verified in Visual Studio Code 1.100.2 with MAUI versions (9.0.70, 9.0.60, 9.0.50, 9.0.0). It cannot be reproduced on the Android(14.0+) platform. Is there any specific configuration needed for replicate the issue? https://github.com/user-attachments/assets/2... </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #29699 <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/dotnet/maui/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
…ctivities (#33805) - [x] Analyze the issue and understand the crash from stack trace - [x] Review PR #29780 fix pattern for destroyed activity context check - [x] Add context destruction check in `PlatformInterop.loadImageFromFont(Context...)` method - [x] Add context destruction check in other `PlatformInterop` methods that use `Glide.with(context)`: - [x] `loadImageFromFile(Context...)` - [x] `loadImageFromUri(Context...)` - [x] `loadImageFromStream(Context...)` - [x] Verify changes compile successfully - [x] Move `isContextDestroyed` and `getActivity` methods to `PlatformInterop` and have `MauiCustomTarget` call them - [x] Run code review - [x] Run CodeQL security scan - [x] Final verification <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> ---- *This section details on the original issue you should resolve* <issue_title>java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity - glide</issue_title> <issue_description>### Description Random issue that I can not reproduce but happening on a small subset of devices according to firebase I believe a previously closed issue maybe the same thing happening: #17549 ### Steps to Reproduce No enough information to say at this point. ### Link to public reproduction project repository _No response_ ### Version with bug 9.0.70 SR7 ### Is this a regression from previous behavior? Yes, this used to work in .NET MAUI ### Last version that worked well 7.0.92 ### Affected platforms Android ### Affected platform versions Android 14 and up ### Did you find any workaround? No ### Relevant log output ```shell Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{######/crc641b109f8ad35faaaf.MainActivity}: java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4206) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4393) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222) at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133) at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773) at android.os.Handler.dispatchMessage(Handler.java:109) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.app.ActivityThread.main(ActivityThread.java:8934) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911) Caused by java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity at com.bumptech.glide.manager.RequestManagerRetriever.assertNotDestroyed(RequestManagerRetriever.java:236) at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:110) at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:92) at com.bumptech.glide.Glide.with(Glide.java:545) at com.microsoft.maui.PlatformInterop.loadImageFromFont(PlatformInterop.java:394) at crc641b109f8ad35faaaf.MainActivity.n_onCreate(MainActivity.java) at crc641b109f8ad35faaaf.MainActivity.onCreate(MainActivity.java:63) at android.app.Activity.performCreate(Activity.java:9079) at android.app.Activity.performCreate(Activity.java:9057) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1531) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4188) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4393) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222) at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133) at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773) at android.os.Handler.dispatchMessage(Handler.java:109) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.app.ActivityThread.main(ActivityThread.java:8934) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911) ```</issue_description> <agent_instructions>Looking at the stack trace above, it looks like the problem started in `loadImageFromFont()`. This PR: * #29780 Fixes the `clear()` code path, can we apply this to the stack trace on this issue?</agent_instructions> ## Comments on the Issue (you are @copilot in this section) <comments> <comment_new><author>@NafeelaNazhir</author><body> This issue has been verified in Visual Studio Code 1.100.2 with MAUI versions (9.0.70, 9.0.60, 9.0.50, 9.0.0). It cannot be reproduced on the Android(14.0+) platform. Is there any specific configuration needed for replicate the issue? https://github.com/user-attachments/assets/2... </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #29699 <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/dotnet/maui/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
…ctivities (#33805) - [x] Analyze the issue and understand the crash from stack trace - [x] Review PR #29780 fix pattern for destroyed activity context check - [x] Add context destruction check in `PlatformInterop.loadImageFromFont(Context...)` method - [x] Add context destruction check in other `PlatformInterop` methods that use `Glide.with(context)`: - [x] `loadImageFromFile(Context...)` - [x] `loadImageFromUri(Context...)` - [x] `loadImageFromStream(Context...)` - [x] Verify changes compile successfully - [x] Move `isContextDestroyed` and `getActivity` methods to `PlatformInterop` and have `MauiCustomTarget` call them - [x] Run code review - [x] Run CodeQL security scan - [x] Final verification <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> ---- *This section details on the original issue you should resolve* <issue_title>java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity - glide</issue_title> <issue_description>### Description Random issue that I can not reproduce but happening on a small subset of devices according to firebase I believe a previously closed issue maybe the same thing happening: #17549 ### Steps to Reproduce No enough information to say at this point. ### Link to public reproduction project repository _No response_ ### Version with bug 9.0.70 SR7 ### Is this a regression from previous behavior? Yes, this used to work in .NET MAUI ### Last version that worked well 7.0.92 ### Affected platforms Android ### Affected platform versions Android 14 and up ### Did you find any workaround? No ### Relevant log output ```shell Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{######/crc641b109f8ad35faaaf.MainActivity}: java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4206) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4393) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222) at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133) at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773) at android.os.Handler.dispatchMessage(Handler.java:109) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.app.ActivityThread.main(ActivityThread.java:8934) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911) Caused by java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity at com.bumptech.glide.manager.RequestManagerRetriever.assertNotDestroyed(RequestManagerRetriever.java:236) at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:110) at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:92) at com.bumptech.glide.Glide.with(Glide.java:545) at com.microsoft.maui.PlatformInterop.loadImageFromFont(PlatformInterop.java:394) at crc641b109f8ad35faaaf.MainActivity.n_onCreate(MainActivity.java) at crc641b109f8ad35faaaf.MainActivity.onCreate(MainActivity.java:63) at android.app.Activity.performCreate(Activity.java:9079) at android.app.Activity.performCreate(Activity.java:9057) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1531) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4188) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4393) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222) at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133) at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773) at android.os.Handler.dispatchMessage(Handler.java:109) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.app.ActivityThread.main(ActivityThread.java:8934) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911) ```</issue_description> <agent_instructions>Looking at the stack trace above, it looks like the problem started in `loadImageFromFont()`. This PR: * #29780 Fixes the `clear()` code path, can we apply this to the stack trace on this issue?</agent_instructions> ## Comments on the Issue (you are @copilot in this section) <comments> <comment_new><author>@NafeelaNazhir</author><body> This issue has been verified in Visual Studio Code 1.100.2 with MAUI versions (9.0.70, 9.0.60, 9.0.50, 9.0.0). It cannot be reproduced on the Android(14.0+) platform. Is there any specific configuration needed for replicate the issue? https://github.com/user-attachments/assets/2... </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #29699 <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/dotnet/maui/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
…ctivities (#33805) - [x] Analyze the issue and understand the crash from stack trace - [x] Review PR #29780 fix pattern for destroyed activity context check - [x] Add context destruction check in `PlatformInterop.loadImageFromFont(Context...)` method - [x] Add context destruction check in other `PlatformInterop` methods that use `Glide.with(context)`: - [x] `loadImageFromFile(Context...)` - [x] `loadImageFromUri(Context...)` - [x] `loadImageFromStream(Context...)` - [x] Verify changes compile successfully - [x] Move `isContextDestroyed` and `getActivity` methods to `PlatformInterop` and have `MauiCustomTarget` call them - [x] Run code review - [x] Run CodeQL security scan - [x] Final verification <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> ---- *This section details on the original issue you should resolve* <issue_title>java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity - glide</issue_title> <issue_description>### Description Random issue that I can not reproduce but happening on a small subset of devices according to firebase I believe a previously closed issue maybe the same thing happening: #17549 ### Steps to Reproduce No enough information to say at this point. ### Link to public reproduction project repository _No response_ ### Version with bug 9.0.70 SR7 ### Is this a regression from previous behavior? Yes, this used to work in .NET MAUI ### Last version that worked well 7.0.92 ### Affected platforms Android ### Affected platform versions Android 14 and up ### Did you find any workaround? No ### Relevant log output ```shell Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{######/crc641b109f8ad35faaaf.MainActivity}: java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4206) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4393) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222) at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133) at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773) at android.os.Handler.dispatchMessage(Handler.java:109) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.app.ActivityThread.main(ActivityThread.java:8934) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911) Caused by java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity at com.bumptech.glide.manager.RequestManagerRetriever.assertNotDestroyed(RequestManagerRetriever.java:236) at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:110) at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:92) at com.bumptech.glide.Glide.with(Glide.java:545) at com.microsoft.maui.PlatformInterop.loadImageFromFont(PlatformInterop.java:394) at crc641b109f8ad35faaaf.MainActivity.n_onCreate(MainActivity.java) at crc641b109f8ad35faaaf.MainActivity.onCreate(MainActivity.java:63) at android.app.Activity.performCreate(Activity.java:9079) at android.app.Activity.performCreate(Activity.java:9057) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1531) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4188) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4393) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222) at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133) at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773) at android.os.Handler.dispatchMessage(Handler.java:109) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.app.ActivityThread.main(ActivityThread.java:8934) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911) ```</issue_description> <agent_instructions>Looking at the stack trace above, it looks like the problem started in `loadImageFromFont()`. This PR: * #29780 Fixes the `clear()` code path, can we apply this to the stack trace on this issue?</agent_instructions> ## Comments on the Issue (you are @copilot in this section) <comments> <comment_new><author>@NafeelaNazhir</author><body> This issue has been verified in Visual Studio Code 1.100.2 with MAUI versions (9.0.70, 9.0.60, 9.0.50, 9.0.0). It cannot be reproduced on the Android(14.0+) platform. Is there any specific configuration needed for replicate the issue? https://github.com/user-attachments/assets/2... </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #29699 <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/dotnet/maui/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
…ctivities (#33805) - [x] Analyze the issue and understand the crash from stack trace - [x] Review PR #29780 fix pattern for destroyed activity context check - [x] Add context destruction check in `PlatformInterop.loadImageFromFont(Context...)` method - [x] Add context destruction check in other `PlatformInterop` methods that use `Glide.with(context)`: - [x] `loadImageFromFile(Context...)` - [x] `loadImageFromUri(Context...)` - [x] `loadImageFromStream(Context...)` - [x] Verify changes compile successfully - [x] Move `isContextDestroyed` and `getActivity` methods to `PlatformInterop` and have `MauiCustomTarget` call them - [x] Run code review - [x] Run CodeQL security scan - [x] Final verification <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> ---- *This section details on the original issue you should resolve* <issue_title>java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity - glide</issue_title> <issue_description>### Description Random issue that I can not reproduce but happening on a small subset of devices according to firebase I believe a previously closed issue maybe the same thing happening: #17549 ### Steps to Reproduce No enough information to say at this point. ### Link to public reproduction project repository _No response_ ### Version with bug 9.0.70 SR7 ### Is this a regression from previous behavior? Yes, this used to work in .NET MAUI ### Last version that worked well 7.0.92 ### Affected platforms Android ### Affected platform versions Android 14 and up ### Did you find any workaround? No ### Relevant log output ```shell Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{######/crc641b109f8ad35faaaf.MainActivity}: java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4206) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4393) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222) at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133) at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773) at android.os.Handler.dispatchMessage(Handler.java:109) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.app.ActivityThread.main(ActivityThread.java:8934) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911) Caused by java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity at com.bumptech.glide.manager.RequestManagerRetriever.assertNotDestroyed(RequestManagerRetriever.java:236) at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:110) at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:92) at com.bumptech.glide.Glide.with(Glide.java:545) at com.microsoft.maui.PlatformInterop.loadImageFromFont(PlatformInterop.java:394) at crc641b109f8ad35faaaf.MainActivity.n_onCreate(MainActivity.java) at crc641b109f8ad35faaaf.MainActivity.onCreate(MainActivity.java:63) at android.app.Activity.performCreate(Activity.java:9079) at android.app.Activity.performCreate(Activity.java:9057) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1531) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4188) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4393) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222) at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133) at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2773) at android.os.Handler.dispatchMessage(Handler.java:109) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.app.ActivityThread.main(ActivityThread.java:8934) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911) ```</issue_description> <agent_instructions>Looking at the stack trace above, it looks like the problem started in `loadImageFromFont()`. This PR: * #29780 Fixes the `clear()` code path, can we apply this to the stack trace on this issue?</agent_instructions> ## Comments on the Issue (you are @copilot in this section) <comments> <comment_new><author>@NafeelaNazhir</author><body> This issue has been verified in Visual Studio Code 1.100.2 with MAUI versions (9.0.70, 9.0.60, 9.0.50, 9.0.0). It cannot be reproduced on the Android(14.0+) platform. Is there any specific configuration needed for replicate the issue? https://github.com/user-attachments/assets/2... </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #29699 <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/dotnet/maui/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Problem
Random crashes occurring on Android devices with the error:
This happens when Glide attempts to clear image targets using a Context whose underlying Activity has been destroyed.
Solution
Added defensive context destruction check in
MauiCustomTarget.clear()before callingGlide.with(context).clear(this).Key Changes:
Added private context lifecycle validation methods to MauiCustomTarget:
isContextDestroyed()- Checks if context/activity is destroyed or finishinggetActivity()- Safely extracts Activity from Context (handles ContextWrapper chains)Protected MauiCustomTarget.clear() operation:
Glide.with(context).clear(this)Behavior:
clear()returns early without attempting to call Glideactivity.isFinishing() || activity.isDestroyed()Example of the fix:
This is a surgical, minimal fix that targets the specific crash location identified in the stack trace while maintaining all existing functionality.
Fixes #29699.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.