Search code examples
javaandroidrenderscriptandroid-renderscript

RenderScript: non fatal RS error, The forEach kernel index is out of bounds


I'm trying to run a simple RenderScript example, but I'm getting the following error:

01-03 16:10:04.723 25608-28248/com.testing.android E/RenderScript_jni: non fatal RS error, The forEach kernel index is out of bounds

The code that's causing this issue is:

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_img_name);

ScriptC_test test = new ScriptC_test(mRS);
Allocation in = Allocation.createFromBitmap(mRS, bitmap);
Allocation out = Allocation.createTyped(mRS, in.getType());

test.forEach_grayscale(in, out);
out.copyTo(bitmap);

My RS file looks like this:

#pragma version(1)
#pragma rs java_package_name(com.testing.android)

uchar4 RS_KERNEL grayscale(uchar4 pixelIn, uint32_t x, uint32_t y) {
    uchar grayscale = (pixelIn.r + pixelIn.g + pixelIn.b) / 3;  // simple average

    uchar4 pixelOut;
    pixelOut.a = pixelIn.a;
    pixelOut.r = grayscale;
    pixelOut.g = grayscale;
    pixelOut.b = grayscale;

    return pixelOut;
}

Does anyone have an idea what might be wrong with the code above?

Thank you!


Solution

  • I fixed this issue by switching from the support library (android.support.v8.renderscript) to the native library (android.renderscript).

    If anyone knows why this makes a difference, please let me know!