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

Glide doesn't loads images in some image views inside a list view #773

Closed
mohan-mishra opened this issue Nov 26, 2015 · 20 comments
Closed
Labels

Comments

@mohan-mishra
Copy link

I have a list view(implemented using the viewholder pattern) which consists of an image view. There would be around 60-70 items in the list. Now the issue is, if I am scrolling the list at a normal rate everything is okay. But when I swipe up the list view and stop it, image is not loaded in some of the image views. Then when I scroll them up or down , image is loaded in them. This issue is very irritating as ours is a very customer centric app and the product is too much image intensive. Can anyone help??

<ImageView
    android:id="@+id/packageImage"
    android:layout_width="match_parent"
    android:layout_height="230dp"
    android:scaleType="fitCenter" />

This is the image view being used in the list view.

And this is how the image is being set

Glide.with(imageView.getContext()).load(imageUrl).into(imageView);
@TWiStErRob
Copy link
Collaborator

From what you described above I don't see anything obviously wrong with your setup.

If you can reproduce this issue consistently (it sounds like you can), add a .listener() and check the logcat output to see what's going on.

@mohan-mishra
Copy link
Author

java.lang.RuntimeException: java.io.EOFException
    at com.bumptech.glide.load.resource.bitmap.Downsampler.decode(Downsampler.java:162)
    at com.bumptech.glide.load.resource.bitmap.StreamBitmapDecoder.decode(StreamBitmapDecoder.java:50)
    at com.bumptech.glide.load.resource.bitmap.StreamBitmapDecoder.decode(StreamBitmapDecoder.java:19)
    at com.bumptech.glide.load.resource.bitmap.ImageVideoBitmapDecoder.decode(ImageVideoBitmapDecoder.java:39)
    ...
Caused by: java.io.EOFException
    at com.android.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:95)
    at com.android.okhttp.internal.http.HttpConnection$ChunkedSource.readChunkSize(HttpConnection.java:514)
    at com.android.okhttp.internal.http.HttpConnection$ChunkedSource.read(HttpConnection.java:495)
    at com.android.okio.RealBufferedSource$1.read(RealBufferedSource.java:168)

This is the exception which occurs when the image is not being loaded

@TWiStErRob
Copy link
Collaborator

From that it looks like the request is being cancelled (but not sure).

Can you please provide more info:

  • android version
  • phone
  • Glide 3.6.1 with no integration libraries?
  • are you loading the same image multiple times or all imageUrls are distinct?
  • context around the Glide load line (e.g. getView method)

@TWiStErRob
Copy link
Collaborator

Hmm, actually square/okhttp#1114 and related issues. Android is using OkHttp built-in, can you please try ot use OkHttp integration to see if that solves your problem?

@mohan-mishra
Copy link
Author

android 5.1.1
Nexus 5
glide 3.6.1 with no integration
No all list view items have distinct urls
getView method.

I used integration library as well but same exception occurs

@TWiStErRob
Copy link
Collaborator

Sorry, I meant the code in getView, not a confirmation... :)

@mohan-mishra
Copy link
Author

The code in getView is the usual boilerplate code using the viewholder and the imageview is set using the Glide function I mentioned earlier

public View getView(int position, View convertView, ViewGroup parent) {
    PackageData item = getItem(position);
    ViewHolder holder = null;

    if (convertView == null) {

        LayoutInflater inflater = (LayoutInflater) getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.holiday_search_result_item, null);

        holder = new ViewHolder(convertView);
        convertView.setTag(holder);

    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    holder.packageImage.setImageResource(R.drawable.hotelnoimage);
// this function has the usual Glide function to set an image which i mentioned earlier
    UIUtilities.setImageUsingGlide(item.getImage(), holder.packageImage);
    return convertView;
}

@TWiStErRob
Copy link
Collaborator

That setImageResource(R.drawable.hotelnoimage) seems out of place: Glide kind of assumes ownership over an ImageView from Glide.with...into() until Glide.clear. Can you please try if the following works well?

    ...
    holder = (ViewHolder) convertView.getTag();
}
Glide
      .with(holder.packageImage.getContext())
      .placeholder(R.drawable.hotelnoimage)
      .load(item.getImage())
      .into(holder.packageImage)
;
return convertView;

@TWiStErRob
Copy link
Collaborator

Also please confirm that this is not true: convertView instanceof ImageView as Glide uses getTag/setTag. Most likely you would've received an exception though...

@mohan-mishra
Copy link
Author

Glide.with(getContext()).load(item.getImages()).placeholder(R.drawable.hotelnoimage).into(holder.packageImage);

this has made loading exceptionally slow

@TWiStErRob
Copy link
Collaborator

Hmm, and we if we ignore placeholder? So just comment out holder.packageImage.setImageResource in the original getView you posted above.

Is there anything else going on in setImageUsingGlide other than that single line?

@TWiStErRob
Copy link
Collaborator

You may be seeing the default crossfade animation as slow. Try adding .dontAnimate() before .into().

@mohan-mishra
Copy link
Author

I understand the animation. But the case when EOF exception arises the image does not loads at all but when the getView of the same list view item is called again(by swiping it out of scope and then again swiping into visibility) the image gets loaded

@TWiStErRob
Copy link
Collaborator

So we need to prevent that EOF from happening, which we don't know why happens. Please try without placeholder (nor Glide.placeholder() nor setImageResource) to see if it's still slow.

@mohan-mishra
Copy link
Author

Why is the placeholder this slow?? Cant it be faster because it will be helpful in case any exception is occuring

@TWiStErRob
Copy link
Collaborator

Based on your responses here's what happens:

  • direct call to setImageResource and no placeholder: sometimes breaks
  • no direct call and no placeholder: everything loads fine
  • no direct call and placeholder: slow loading

Is this correct? Please confirm explicitly, it's hard to go on assumptions.

What's your placeholder (R.drawable.hotelnoimage)? (file size, type, dimensions)

@TWiStErRob
Copy link
Collaborator

Closing this for now, feel free to reopen if you need more help regarding this issue and can provide more infromation.

@Dipongkar12
Copy link

W/Glide: Load failed for https://firebasestorage.googleapis.com/v0/b/mfree-9290a.appspot.com/o/placeholder.jpg?alt=media&token=45452c04-e97f-430c-9be2-2b1f31446a50 with size [80x80]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 cause:
java.net.SocketTimeoutException(failed to connect to firebasestorage.googleapis.com/2404:6800:4007:80a::200a (port 443) from /fec0::68bb:adbd:5e34:9bd3 (port 36718) after 2500ms)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, REMOTE
There was 1 cause:
java.net.SocketTimeoutException(failed to connect to firebasestorage.googleapis.com/2404:6800:4007:80a::200a (port 443) from /fec0::68bb:adbd:5e34:9bd3 (port 36718) after 2500ms)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
There was 1 cause:
java.net.SocketTimeoutException(failed to connect to firebasestorage.googleapis.com/2404:6800:4007:80a::200a (port 443) from /fec0::68bb:adbd:5e34:9bd3 (port 36718) after 2500ms)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class java.net.SocketTimeoutException: failed to connect to firebasestorage.googleapis.com/2404:6800:4007:80a::200a (port 443) from /fec0::68bb:adbd:5e34:9bd3 (port 36718) after 2500ms
2020-04-08 12:54:03.098 12299-12299/com.example.mfree I/Glide: Root cause (1 of 1)
java.net.SocketTimeoutException: failed to connect to firebasestorage.googleapis.com/2404:6800:4007:80a::200a (port 443) from /fec0::68bb:adbd:5e34:9bd3 (port 36718) after 2500ms
at libcore.io.IoBridge.connectErrno(IoBridge.java:185)
at libcore.io.IoBridge.connect(IoBridge.java:129)
at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:137)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:390)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436)
at java.net.Socket.connect(Socket.java:621)
at com.android.okhttp.internal.Platform.connectSocket(Platform.java:145)
at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:141)
at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:112)
at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:184)
at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126)
at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:461)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:127)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:89)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:26)
at com.bumptech.glide.load.data.HttpUrlFetcher.loadDataWithRedirects(HttpUrlFetcher.java:100)
at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:56)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:100)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.startNextOrFail(MultiModelLoader.java:164)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.onLoadFailed(MultiModelLoader.java:154)
at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:62)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:100)
at com.bumptech.glide.load.engine.SourceGenerator.startNextLoad(SourceGenerator.java:70)
at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:63)
at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310)
at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:279)
at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:234)
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:764)
at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:393)

what can be the solution?

@AdityaVSM
Copy link

@Dipongkar12 Try this
Glide.with(this).load(url).dontAnimate().into(imageView)

Hope this helps

@TGar21
Copy link

TGar21 commented Sep 2, 2023

Hi.
Didn't help for me.
With or without placeholder, it doesn't load.

I am loading 4 images synchronously and at least one of them is not loaded each tme.

Glide
            .with(context)
            .asBitmap()
            .load(photoFile)
            .override(1080, 600)
            .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
//            .placeholder(R.drawable.image_placeholder)
            .dontAnimate()
            .into(showImageView.getContent())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants