有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java RenderScript导致“缺少.rs.global_条目”的应用程序崩溃

我正在使用RenderScript旋转一组图像。应用程序突然崩溃,发出致命信号11。有100个“D/RenderScript”﹕ 丢失的日志中的rs.global_entries from shared object”消息。还可以看到内存显著增加。 原因是什么?如何解决它

我正在使用三星GaleryTab和安卓 4.4.2。我在下面列出了Gradle、Rs、Java和logcat输出

compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
    minSdkVersion 18
    targetSdkVersion 21
    renderscriptTargetApi 18
    renderscriptSupportModeEnabled true


 #pragma version(1)
#pragma rs_fp_relaxed
#pragma rs java_package_name(com.models)

rs_allocation inImage;
int inWidth;
int inHeight;

uchar4 __attribute__ ((kernel)) rotate_270_clockwise (uchar4 in, uint32_t x, uint32_t y) {
    uint32_t inX  = inWidth - 1 - y;
    uint32_t inY = x;
    const uchar4 *out = rsGetElementAt(inImage, inX, inY);
    return *out;
}

uchar4 __attribute__ ((kernel)) rotate_180_clockwise (uchar4 in, uint32_t x, uint32_t y) {

    uint32_t inX = inWidth - 1 - x;
    uint32_t inY = inHeight - 1 - y;

    const uchar4 *out = rsGetElementAt(inImage, inX, inY);
    return *out;
}

uchar4 __attribute__ ((kernel)) rotate_90_clockwise (uchar4 in, uint32_t x, uint32_t y) {
    uint32_t inX = y;
    uint32_t inY = inHeight - 1 - x;

    const uchar4 *out = rsGetElementAt(inImage, inX, inY);
    return *out;
}

uchar4 __attribute__ ((kernel)) rotate_0_clockwise (uchar4 in, uint32_t x, uint32_t y) {
    uint32_t inX = x;
    uint32_t inY =  y;

    const uchar4 *out = rsGetElementAt(inImage, inX, inY);
    return *out;
}

Java代码

public Bitmap rotateBitmap(Bitmap bitmap, Activity activity, int angle, boolean recycle) {
    Bitmap target = null;
    try {
        RenderScript rs = RenderScript.create(activity, RenderScript.ContextType.DEBUG);
        ScriptC_rotator script = new ScriptC_rotator(rs);
        script.set_inWidth(bitmap.getWidth());
        script.set_inHeight(bitmap.getHeight());
        Allocation sourceAllocation = Allocation.createFromBitmap(rs, bitmap,
                Allocation.MipmapControl.MIPMAP_NONE,
                Allocation.USAGE_SCRIPT);
        if (recycle)
            bitmap.recycle();
        script.set_inImage(sourceAllocation);

        //270 and 90
        int targetHeight = bitmap.getWidth();
        int targetWidth = bitmap.getHeight();
        if (angle == 180 || angle == 0) {
            targetHeight = bitmap.getHeight();
            targetWidth = bitmap.getWidth();
        }

        Bitmap.Config config = bitmap.getConfig();
        target = Bitmap.createBitmap(targetWidth, targetHeight, config);
        final Allocation targetAllocation = Allocation.createFromBitmap(rs, target,
                Allocation.MipmapControl.MIPMAP_NONE,
                Allocation.USAGE_SCRIPT);
        if (angle == 90)
            script.forEach_rotate_90_clockwise(targetAllocation, targetAllocation);
        else if (angle == 180)
            script.forEach_rotate_180_clockwise(targetAllocation, targetAllocation);
        else if (angle == 270)
            script.forEach_rotate_270_clockwise(targetAllocation, targetAllocation);
        else
            script.forEach_rotate_0_clockwise(targetAllocation, targetAllocation);

        targetAllocation.copyTo(target);
        rs.destroy();
    } catch (Exception e) {
        Log.d("myApp", "rotateBitmap- render script " + e.getMessage());
    }

    return target;
}

日志

 04-19 22:04:02.219  30377-30377/com.champ D/myApp﹕ processActionUp-scaleDetector.isInProgress()
    04-19 22:04:04.259  30377-30761/com.champ D/RenderScript﹕ Missing .rs.global_entries from shared object
    04-19 22:04:04.259  30377-30761/com.champ D/RenderScript﹕ Missing .rs.global_entries from shared object
    04-19 22:04:04.269  30377-30761/com.champ D/RenderScript﹕ Missing .rs.global_entries from shared object
    04-19 22:04:04.269  30377-30761/com.champ D/RenderScript﹕ Missing .rs.global_entries from shared object
    04-19 22:04:04.279  30377-30761/com.champ D/RenderScript﹕ Missing .rs.global_entries from shared object
    04-19 22:04:04.279  30377-30761/com.champ D/RenderScript﹕ Missing .rs.global_entries from shared object
    04-19 22:04:04.289  30377-30761/com.champ D/RenderScript﹕ Missing .rs.global_entries from shared object
    04-19 22:04:04.319  30377-30377/com.champ D/myApp﹕ processActionUp
    04-19 22:04:04.319  30377-30377/com.champ D/myApp﹕ processActionUp-scaleDetector.isInProgress()
    04-19 22:04:07.389  30377-30377/com.champ D/dalvikvm﹕ GC_FOR_ALLOC freed 2335K, 9% free 33300K/36444K, paused 26ms, total 26ms
    04-19 22:04:07.389  30377-30377/com.champ I/dalvikvm-heap﹕ Grow heap (frag case) to 33.607MB for 320336-byte allocation
    04-19 22:04:07.409  30377-30377/com.champ D/dalvikvm﹕ GC_FOR_ALLOC freed 3K, 9% free 33609K/36760K, paused 20ms, total 20ms
    04-19 22:04:07.419  30377-30761/com.champ D/RenderScript﹕ Missing .rs.global_entries from shared object
    04-19 22:04:07.479  30377-30761/com.champ D/RenderScript﹕ Missing .rs.global_entries from shared object
    04-19 22:04:07.489  30377-30761/com.champ D/RenderScript﹕ Missing .rs.global_entries from shared object
    04-19 22:04:07.489  30377-30761/com.champ D/RenderScript﹕ Missing .rs.global_entries from shared object
    04-19 22:04:07.499  30377-30761/com.champ D/RenderScript﹕ Missing .rs.global_entries from shared object
    04-19 22:04:07.509  30377-30761/com.champ D/RenderScript﹕ Missing .rs.global_entries from shared object
    04-19 22:04:07.509  30377-30761/com.champ D/RenderScript﹕ Missing .rs.global_entries from shared object
    04-19 22:04:07.519  30377-30761/com.champ D/RenderScript﹕ Missing .rs.global_entries from shared object
    04-19 22:04:07.529  30377-30761/com.champ D/RenderScript﹕ Missing .rs.global_entries from shared object
    04-19 22:04:07.529  30377-30761/com.champ D/RenderScript﹕ Missing .rs.global_entries from shared object
    04-19 22:04:07.559  30377-30377/com.champ D/myApp﹕ processActionUp
    04-19 22:04:07.559  30377-30377/com.champ D/myApp﹕ processActionUp-scaleDetector.isInProgress()
    04-19 22:04:11.709  30377-30377/com.champ D/dalvikvm﹕ GC_FOR_ALLOC freed 1496K, 12% free 32489K/36760K, paused 20ms, total 20ms
    04-19 22:04:11.759  30377-30377/com.champ D/dalvikvm﹕ GC_FOR_ALLOC freed 20K, 11% free 32843K/36760K, paused 18ms, total 19ms
    04-19 22:04:11.759  30377-30377/com.champ I/dalvikvm-heap﹕ Grow heap (frag case) to 33.221MB for 383696-byte allocation
    04-19 22:04:11.779  30377-30386/com.champ D/dalvikvm﹕ GC_FOR_ALLOC freed <1K, 11% free 33217K/37136K, paused 16ms, total 17ms
    04-19 22:04:11.779  30377-30761/com.champ D/RenderScript﹕ Missing .rs.global_entries from shared object
    04-19 22:04:11.789  30377-30763/com.champ A/libc﹕ Fatal signal 11 (SIGSEGV) at 0x66082000 (code=1), thread 30763 (AsyncTask #4)

共 (1) 个答案

  1. # 1 楼答案

    停止创建RenderScript上下文(android.RenderScript),并在每次调用一个rotate*()函数时加载脚本(即ScriptC_rotator)。您应该缓存这些对象,因为它们都不是轻量级的。这将减少日志记录,并减少内存碎片(因为您一直在加载/卸载脚本)

    SIGSEGV有点让人困惑,但这可能是因为您的系统中存在越界内存访问。rs文件。我看到您正在创建调试上下文。当您捕获此日志时,它是否已就位,或者是后来添加的内容?考虑到由于旋转而交换宽度/高度,我认为您在中使用了错误的Y/X值。玉米仁。考虑使用RSDebug来打印出正在写入的索引,并且您可能会看到它最终失败的地方(并且它确实超出了界限)。p>