bumptech / bumptech/glide

CalledFromWrongThreadException when load from cache

Open
#4,457 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
35k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
8

Description

**Glide Version**:4.10.0

**Integration libraries**:3.12.6

**Device/Android Version**:SLA-AL00;Android 7.0,level 24

**Issue details / Repro steps / Use case background**:

**className:** Engine.java
```java
public LoadStatus load(
GlideContext glideContext,
Object model,
Key signature,
int width,
int height,
Class resourceClass,
Class transcodeClass,
Priority priority,
DiskCacheStrategy diskCacheStrategy,
Map, Transformation> transformations,
boolean isTransformationRequired,
boolean isScaleOnlyOrNoTransform,
Options options,
boolean isMemoryCacheable,
boolean useUnlimitedSourceExecutorPool,
boolean useAnimationPool,
boolean onlyRetrieveFromCache,
ResourceCallback cb,
Executor callbackExecutor) {
long startTime = VERBOSE_IS_LOGGABLE ? LogTime.getLogTime() : 0;

...

// Avoid calling back while holding the engine lock, doing so makes it easier for callers to
// deadlock.
cb.onResourceReady(memoryResource, DataSource.MEMORY_CACHE);
return null;
}
```

when memoryResource not null , why not call onResourceReady with callbackExecutor.
it cause `CalledFromWrongThreadException `

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

call glide.with in sub thread
```java
Glide.with(mParent).asDrawable()
.apply(diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
.load(Uri.parse(url))
.into(new CustomTarget() {
@Override
public void onResourceReady(@NonNull Drawable drawable,
@Nullable Transition
transition) {
...
imageView.setVisibility(View.VISIBLE);
imageView.setImageDrawable(drawable);
...
}

@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
...
}

});
```

**Layout XML**:
```xml

Contributor guide

Open the contributing guide

Research direction

Start with Engine.java's load method and compare the memory-cache path with the callback stack through SingleRequest.java and CustomTarget.java. Reproduce the cache-hit case from the reported background-thread Glide call and determine whether the callback reaches the Android view on the correct thread; done means the reported CalledFromWrongThreadException is addressed without breaking cache-hit delivery.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.