Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] System.ObjectDisposedException: ObjectDisposed_StreamClosed #21461

Closed
MichaelFrenkel opened this issue Mar 26, 2024 · 1 comment
Closed
Labels
area-controls-image Image control migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 s/needs-repro Attach a solution or code which reproduces the issue s/triaged Issue has been reviewed t/bug Something isn't working

Comments

@MichaelFrenkel
Copy link

Description

Image Stream closes while loading

Steps to Reproduce

Hard one to reproduce, did try to create a repro but couldn't. Seems like it's happening because of ImageSource.FromResource, ImageSource.FromStream, under the hood stream loading func is wrapped with Task.Run, if I instead use new StreamImageSource { Stream = _ => GetStreamLogic() } then no crash.
not sure, probably Stream closes while PlatformInterop.LoadImageFromStream(imageView, stream, callback); is still executing here.
could it be sth like this https://kevingosse.medium.com/c-using-gc-keepalive-in-async-methods-8d20fd79f0a0?

Link to public reproduction project repository

No response

Version with bug

8.0.10 SR3

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

in my case, the following workarounds helped:

  1. instead of ImageSource.FromResource/FromStream use new StreamImageSource { Stream = _ => GetStreamLogic() }
  2. use MauiImage instead of EmbeddedResource if it's suitable
  3. you can register your own StreamImageSourceService and reimplement LoadDrawableAsync, for instance, use Xamarin approach
  4. use 3rd party library, for instance, FFImageLoading

Relevant log output

System.ObjectDisposedException: ObjectDisposed_StreamClosed
  at System.IO.UnmanagedMemoryStream.ReadCore(Span`1 )
  at System.IO.UnmanagedMemoryStream.Read(Byte[] , Int32 , Int32 )
  at Android.Runtime.InputStreamAdapter.Read(Byte[] , Int32 , Int32 )
  at Java.IO.InputStream.n_Read_arrayBII(IntPtr jnienv, IntPtr native__this, IntPtr native_b, Int32 off, Int32 len)
  at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLII_I(_JniMarshal_PPLII_I callback, IntPtr jnienv, IntPtr klazz, IntPtr p0, Int32 p1, Int32 p2)


0   dalvik.system.VMStack.getThreadStackTrace(VMStack.java:-2)
1   java.lang.Thread.getStackTrace(Thread.java:1841)
2   java.lang.Thread.getAllStackTraces(Thread.java:1909)
3   com.microsoft.appcenter.crashes.Crashes.saveUncaughtException(Crashes.java:1157)
4   com.microsoft.appcenter.crashes.WrapperSdkExceptionManager.saveWrapperException(WrapperSdkExceptionManager.java:58)
5   mono.android.runtime.InputStreamAdapter.n_read(InputStreamAdapter.java:-2)
6   mono.android.runtime.InputStreamAdapter.read(InputStreamAdapter.java:57)
7   com.bumptech.glide.load.resource.bitmap.RecyclableBufferedInputStream.fillbuf(RecyclableBufferedInputStream.java:173)
8   com.bumptech.glide.load.resource.bitmap.RecyclableBufferedInputStream.read(RecyclableBufferedInputStream.java:230)
9   com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser$StreamReader.getUInt8(DefaultImageHeaderParser.java:565)
10  com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser$StreamReader.getUInt16(DefaultImageHeaderParser.java:575)
11  com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser.getType(DefaultImageHeaderParser.java:100)
12  com.bumptech.glide.load.resource.bitmap.DefaultImageHeaderParser.getType(DefaultImageHeaderParser.java:72)
13  com.bumptech.glide.load.ImageHeaderParserUtils$1.getTypeAndRewind(ImageHeaderParserUtils.java:49)
14  com.bumptech.glide.load.ImageHeaderParserUtils.getTypeInternal(ImageHeaderParserUtils.java:121)
15  com.bumptech.glide.load.ImageHeaderParserUtils.getType(ImageHeaderParserUtils.java:43)
16  com.bumptech.glide.load.resource.drawable.AnimatedImageDecoder.handles(AnimatedImageDecoder.java:60)
17  com.bumptech.glide.load.resource.drawable.AnimatedImageDecoder$StreamAnimatedImageDecoder.handles(AnimatedImageDecoder.java:130)
18  com.bumptech.glide.load.resource.drawable.AnimatedImageDecoder$StreamAnimatedImageDecoder.handles(AnimatedImageDecoder.java:118)
19  com.bumptech.glide.load.engine.DecodePath.decodeResourceWithList(DecodePath.java:90)
20  com.bumptech.glide.load.engine.DecodePath.decodeResource(DecodePath.java:70)
21  com.bumptech.glide.load.engine.DecodePath.decode(DecodePath.java:59)
22  com.bumptech.glide.load.engine.LoadPath.loadWithExceptionList(LoadPath.java:76)
23  com.bumptech.glide.load.engine.LoadPath.load(LoadPath.java:57)
24  com.bumptech.glide.load.engine.DecodeJob.runLoadPath(DecodeJob.java:539)
25  com.bumptech.glide.load.engine.DecodeJob.decodeFromFetcher(DecodeJob.java:503)
26  com.bumptech.glide.load.engine.DecodeJob.decodeFromData(DecodeJob.java:489)
27  com.bumptech.glide.load.engine.DecodeJob.decodeFromRetrievedData(DecodeJob.java:434)
28  com.bumptech.glide.load.engine.DecodeJob.onDataFetcherReady(DecodeJob.java:399)
29  com.bumptech.glide.load.engine.SourceGenerator.onDataReadyInternal(SourceGenerator.java:211)
30  com.bumptech.glide.load.engine.SourceGenerator$1.onDataReady(SourceGenerator.java:101)
31  com.microsoft.maui.glide.stream.GlideInputStreamModelLoader$1.loadData(GlideInputStreamModelLoader.java:23)
32  com.bumptech.glide.load.engine.SourceGenerator.startNextLoad(SourceGenerator.java:95)
33  com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:88)
34  com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:311)
35  com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:277)
36  com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:235)
37  java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
38  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
39  com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:424)
40  java.lang.Thread.run(Thread.java:1012)
41  com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultPriorityThreadFactory$1.run(GlideExecutor.java:383)
@MichaelFrenkel
Copy link
Author

the issue is hard to reproduce. The workarounds helped us reduce crashes by 90% but they were still in place until maui 8.0.40, seems like it was fixed in this version.

@dotnet-policy-service dotnet-policy-service bot removed the s/no-recent-activity Issue has had no recent activity label Jun 26, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jul 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-image Image control migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 s/needs-repro Attach a solution or code which reproduces the issue s/triaged Issue has been reviewed t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants