bumptech / glide

An image loading and caching library for Android focused on smooth scrolling
https://bumptech.github.io/glide/
Other
34.47k stars 6.11k forks source link

java.lang.arithmeticexception divide by zero #4665

Open yangjiantao opened 2 years ago

yangjiantao commented 2 years ago

Glide Version: 4.12.0

Integration libraries: okhttp3

Device/Android Version: Pixel XL - API 30

Issue details / Repro steps / Use case background:

Repro steps:

  1. Load a web image whose width is greater than its height (for example: 125x31)
  2. Assign shapeDrawable to placeHolder when loading

Glide load line / GlideModule (if any) / list Adapter code (if any):

// placeHolder is a shapeDrawble
Glide.with(imageView).load(url).placeholder(placeHolder).into(imageView)

Layout XML:

<ImageView
            android:id="@+id/titleImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

Stack trace / LogCat:

7D755E3E-4D5A-4332-826B-1AA0DA599ED6

2021-10-12 21:17:19.843 7924-7924/com.example.cms I/Glide: Root cause (16 of 18)
    java.lang.ArithmeticException: divide by zero
        at com.bumptech.glide.load.resource.bitmap.Downsampler.calculateScaling(Downsampler.java:493)
        at com.bumptech.glide.load.resource.bitmap.Downsampler.decodeFromWrappedStreams(Downsampler.java:308)
        at com.bumptech.glide.load.resource.bitmap.Downsampler.decode(Downsampler.java:248)
        at com.bumptech.glide.load.resource.bitmap.Downsampler.decode(Downsampler.java:219)
        at com.bumptech.glide.load.resource.bitmap.ParcelFileDescriptorBitmapDecoder.decode(ParcelFileDescriptorBitmapDecoder.java:35)
        at com.bumptech.glide.load.resource.bitmap.ParcelFileDescriptorBitmapDecoder.decode(ParcelFileDescriptorBitmapDecoder.java:15)
        at com.bumptech.glide.load.engine.DecodePath.decodeResourceWithList(DecodePath.java:92)
        at com.bumptech.glide.load.engine.DecodePath.decodeResource(DecodePath.java:70)
        at com.bumptech.glide.load.engine.DecodePath.decode(DecodePath.java:59)
        at com.bumptech.glide.load.engine.LoadPath.loadWithExceptionList(LoadPath.java:76)
        at com.bumptech.glide.load.engine.LoadPath.load(LoadPath.java:57)
        at com.bumptech.glide.load.engine.DecodeJob.runLoadPath(DecodeJob.java:529)
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromFetcher(DecodeJob.java:493)
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromData(DecodeJob.java:479)
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromRetrievedData(DecodeJob.java:430)
        at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherReady(DecodeJob.java:394)
        at com.bumptech.glide.load.engine.SourceGenerator.onDataFetcherReady(SourceGenerator.java:176)
        at com.bumptech.glide.load.engine.DataCacheGenerator.onDataReady(DataCacheGenerator.java:94)
        at com.bumptech.glide.load.model.FileLoader$FileFetcher.loadData(FileLoader.java:72)
        at com.bumptech.glide.load.engine.DataCacheGenerator.startNext(DataCacheGenerator.java:74)
        at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:50)
        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:311)
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromRetrievedData(DecodeJob.java:438)
        at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherReady(DecodeJob.java:394)
        at com.bumptech.glide.load.engine.SourceGenerator.onDataFetcherReady(SourceGenerator.java:176)
        at com.bumptech.glide.load.engine.DataCacheGenerator.onDataReady(DataCacheGenerator.java:94)
        at com.bumptech.glide.load.model.FileLoader$FileFetcher.loadData(FileLoader.java:72)
        at com.bumptech.glide.load.engine.DataCacheGenerator.startNext(DataCacheGenerator.java:74)
        at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:50)
        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:311)
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromRetrievedData(DecodeJob.java:438)
        at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherReady(DecodeJob.java:394)
        at com.bumptech.glide.load.engine.SourceGenerator.onDataFetcherReady(SourceGenerator.java:176)
        at com.bumptech.glide.load.engine.DataCacheGenerator.onDataReady(DataCacheGenerator.java:94)
        at com.bumptech.glide.load.model.ByteBufferFileLoader$ByteBufferFetcher.loadData(ByteBufferFileLoader.java:62)
        at com.bumptech.glide.load.engine.DataCacheGenerator.startNext(DataCacheGenerator.java:74)
        at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:50)
        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:311)
        at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:280)
        at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:235)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)
        at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:393)
Shubhamsdr3 commented 2 years ago

I also faced this same issue however when I fix the size of ImageView it worked.

After a little deep dive I figured out this happens when we use placeholder without any size pre-defined.

This is working fine once I set up a size of placeholder or fix the size of image view.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

StainlessStlRat commented 1 year ago

Indeed not using a placeholder seems to fix it, but it only fails on the second image of two images in one View. My placeholder is a circular progress drawable and it works fine in my other uses as well.

StainlessStlRat commented 1 year ago

Making the imageView a fixed size fixes it as well, but shouldn't have to do that!