AsyncTask Android 中的致命信号 6 (SIGABRT)
Posted
技术标签:
【中文标题】AsyncTask Android 中的致命信号 6 (SIGABRT)【英文标题】:Fatal signal 6 (SIGABRT) in AsyncTask Android 【发布时间】:2020-05-01 02:25:23 【问题描述】:我在 asynctask 中压缩 Bitmap 并通过 Bundle 将其发送到另一个活动,我遇到了这个崩溃。我在我的代码中调用 Bitmap.recycle() 。有时它可以正常工作,这是我的 Logcat 输出。
Called getHeight() on a recycle()'d bitmap! This is undefined behavior!
2020-01-14 16:25:56.863 21779-22017/ W/Bitmap: Called getWidth() on a recycle()'d bitmap! This is undefined behavior!
2020-01-14 16:25:56.863 21779-22017/ W/Bitmap: Called getWidth() on a recycle()'d bitmap! This is undefined behavior!
2020-01-14 16:25:56.863 21779-22017/ W/Bitmap: Called getHeight() on a recycle()'d bitmap! This is undefined behavior!
2020-01-14 16:25:56.863 21779-22017/ W/Bitmap: Called getWidth() on a recycle()'d bitmap! This is undefined behavior!
2020-01-14 16:25:56.863 21779-22017/ W/Bitmap: Called getHeight() on a recycle()'d bitmap! This is undefined behavior!
2020-01-14 16:25:56.863 21779-22017/ W/Bitmap: Called getWidth() on a recycle()'d bitmap! This is undefined behavior!
2020-01-14 16:25:56.863 21779-22017/ W/Bitmap: Called getHeight() on a recycle()'d bitmap! This is undefined behavior!
2020-01-14 16:25:56.863 21779-22017/ W/Bitmap: Called getConfig() on a recycle()'d bitmap! This is undefined behavior!
2020-01-14 16:25:56.863 21779-22017/ W/Bitmap: Called getConfig() on a recycle()'d bitmap! This is undefined behavior!
2020-01-14 16:25:56.863 21779-22017/ W/Bitmap: Called hasAlpha() on a recycle()'d bitmap! This is undefined behavior!
2020-01-14 16:25:56.864 21779-22017/ A/Bitmap: Error, cannot access an invalid/free'd bitmap here!
2020-01-14 16:25:56.864 21779-22017/ A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 22017 (AsyncTask #5), pid 21779
这是压缩图像的代码
private static void compressImage(final Bitmap bitmap, final Callback<Bitmap> gbCallback)
new AsyncTask<Void, Void, Bitmap>()
protected void onPreExecute()
@Override
protected Bitmap doInBackground(Void... params)
Bitmap image = getScaledImageCopy(bitmap);
if (image != null)
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 80, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
image = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
return image;
else
return null;
@Override
protected void onPostExecute(Bitmap bitmap)
gbCallback.call(bitmap);
.execute(null, null, null);
private static Bitmap getScaledImageCopyForUGC(Bitmap image)
try
int height = image.getHeight();
int width = image.getWidth();
return Bitmap.createScaledBitmap(image, 400, (400 * height) / width, true);
catch (Exception e)
if (image != null)
return Bitmap.createScaledBitmap(image, 300, 300, true);
else
return null;
【问题讨论】:
显示用于压缩位图的代码 代码添加@TusharMonirul 这能回答你的问题吗? What is fatal signal 6 in android logcat 【参考方案1】:位图似乎已经被回收了。您不能使用回收的位图。您需要确保在compressImage
中传递的位图未被回收。现在您可以检查位图是否被回收以避免错误。
if(!bitmap.isRecycled())
//bitmap is not recycled
else
//bitmap is recycled, use a default placeholder
【讨论】:
以上是关于AsyncTask Android 中的致命信号 6 (SIGABRT)的主要内容,如果未能解决你的问题,请参考以下文章
E/AndroidRuntime:致命异常:Android 的 AsyncTask #1 错误