Tencent / Tencent/libpag

Android 原生 红米A3 replaceImageByName 卡死

Open
#2,990 2 comments 0 reactions 1 assignee View on GitHub

@kevingpqi123 is already working on this.

Since Sep 1, 2025.

Dominant language
HTML
Stars
5.8k
Forks
531
Avg merge
8d 55m
Merged PRs (30d)
17

Description

【版本信息】

4.4.20

【平台信息】

Android 原生 红米A3

【预期的表现】

替换图片的时候, 替换正确的图片

【实际的情况】

ANR 卡死

【Demo及附件】

 GlideArms.with(mContext)
            .asBitmap()
            .circleCrop()
            .load(headUrl != null ? headUrl : defaultRes) // 统一加载逻辑
            .addListener(new RequestListener<Bitmap>() {
                @Override
                public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
                    // 加载失败时:用默认图重试(可选,根据需求决定是否需要)
                    if (defaultRes != 0) {
                        loadDefaultImage(pagFile, key, pagImg, defaultRes);
                    }
                    return true; // 拦截默认错误处理
                }

                @Override
                public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
                    // 4. PAG 操作安全校验:防止页面销毁后执行

// if (mContext.isDestroyed() || pagFile.isDestroyed()) {
// resource.recycle(); // 释放 Bitmap
// return true;
// }

                    try {
                        PAGImage pagImage = PAGImage.FromBitmap(resource);
                        pagFile.replaceImageByName(key, pagImage);
                        pagImg.setComposition(pagFile);
                        // 5. 释放 PAGImage(关键!避免内存泄漏)
                        if (pagImage != null) {
                            pagImage.release();
                        }
                    } catch (Exception e) {
                        // 6. 捕获所有异常:避免崩溃,日志备查
                        Log.e("replacePagImg", "替换图片失败", e);
                        resource.recycle(); // 加载成功但 PAG 处理失败时释放 Bitmap
                    }
                    return true; // 拦截默认成功处理
                }
            })
            .into(new SimpleTarget<Bitmap>() {
                @Override
                public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                    // 这里无需重复处理,交给 Listener 统一管理
                }
            });
}

replaceImageByName 这里卡住

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.