Reputation: 11419
I use RenderScript for bluring and for other operations. It works fine on most phones. On some phones I randomly get the following exception:
android.renderscript.RSInvalidStateException:
Received a message from the script with no message handler installed. at android.renderscript.RenderScript$MessageThread.run(RenderScript.java:1087)
It is very hard to reproduce it but on Crashlytics I can see that it happened 75% on Hudl2, 17% on Asus and 8% on Acer. So all cheap phones.
Does anyone know what the cause is and how to fix it?
This is the code that runs on Jellybean+
@Override
protected Bitmap blurBitmap(final Bitmap bitmap, final Bitmap argbBitmap, final Bitmap blurredBitmap) {
final RenderScript renderScript = RenderScript.create(mContext);
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript));
// Allocate memory for Renderscript to work with
final Allocation input = Allocation.createFromBitmap(renderScript, argbBitmap);
final Allocation output = Allocation.createFromBitmap(renderScript, blurredBitmap);
script.setInput(input);
script.setRadius(mRadius);
script.forEach(output);
output.copyTo(blurredBitmap);
renderScript.destroy();
bitmap.recycle();
argbBitmap.recycle();
return blurredBitmap;
}
Upvotes: 3
Views: 2213
Reputation: 1469
I've seen this on some old devices, it's a bug. It's not a bug in the code above.
However, there is a major problem with the code above. You really, really do not want to be creating and destroying RS contexts every time you want to do a small operation. This is something that should be done once for an application's lifecycle. Re-using the context will give you a major performance win. It will also protect you from the bug you are seeing as it will only potentially occur on application teardown.
It it then continues to give you problems, you can work around it by installing a message handler to soak up the sporadic message on exit.
Upvotes: 3