-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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 NPE #2413
Comments
Thanks for your feedback! Can you provide more details:
|
|
Sorry, I've tried with kotlin
but cannot reproduce this crash. Are you trying (or maybe potentially caused by some lifecycle logic) to use an image request that maybe already removed from Or maybe you can waiting for @sjudd for help 😝 |
sorry , i do not known this case. sometimes crash. |
Bumping this up, I'm having the same issue (on Glide 4.1.1), seems to happen after a request times out.
|
Let me know if you can reproduce this. One way I think this can happen is if a |
I disabled cache and was able to reproduce it 100% of times. You are right, it seems in my case it happens because when it fails for the first time, we retry the request. When it fails for a second time, that's when the crash happens. Removing the retry stops the crashes. Thanks! I'll consider this as solved for me :) |
Can you show the retry you're using? You actually can retry in a DataFetcher, you just can't call the callbacks until the retries are finished. |
This was probably a terrible idea, in hindsight, but here goes: GlideApp.with(Application.getContext())
.load(url)
.placeholder(defaultImageRes)
.error(defaultImageRes)
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable final GlideException e, final Object model,
final Target<Drawable> target, final boolean isFirstResource) {
GlideApp.with(imageView)
.load(url)
.placeholder(defaultImageRes)
.error(defaultImageRes)
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable final GlideException e, final Object model,
final Target<Drawable> target, final boolean isFirstResource) {
if (onError != null) {
onError.run();
}
return false;
}
@Override
public boolean onResourceReady(final Drawable resource, final Object model,
final Target<Drawable> target, final DataSource dataSource,
final boolean isFirstResource) {
if (onSuccess != null) {
onSuccess.run();
}
return false;
}
})
.into(imageView);
return false;
}
@Override
public boolean onResourceReady(final Drawable resource, final Object model,
final Target<Drawable> target, final DataSource dataSource, final boolean isFirstResource) {
if (onSuccess != null) {
onSuccess.run();
}
return false;
}
})
.into(imageView); |
Ah I got it, thanks that's super helpful. So I think you actually can make that work by posting your second load in onLoadFailed: @Override
public boolean onLoadFailed(@Nullable final GlideException e, final Object model,
final Target<Drawable> target, final boolean isFirstResource) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Glide.with(imageView)....
});
} In your case this error occurs because your second load actually recycles the first request while the first request is in the middle of running it's load failed logic so that by the time your request listener finishes running, all of its state has been cleared out. I can't trivially fix that, but I can probably at least make it throw a reasonable exception most of the time that will make it more obvious what isn't working. |
Yeah, that actually works, awesome! Thanks for the help, hope it helps @liufsd as well. |
version
crash:
The text was updated successfully, but these errors were encountered: