Commit 828a34f
Fix Glide IllegalArgumentException in PlatformInterop for destroyed activities (#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>1 parent 5c6da6c commit 828a34f
File tree
4 files changed
+57
-690
lines changed- src/Core/AndroidNative
- build/reports/problems
- maui/src/main/java/com/microsoft/maui
- glide
4 files changed
+57
-690
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
388 | 388 | | |
389 | 389 | | |
390 | 390 | | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
0 commit comments