Be sure to call 'destroy()' on your Renderscript rs variable when you're
done with it (just before the 'return bm' statement).
It wouldn't hurt to call 'destroy()' on the 'input' and 'ouput' variables
as well when you're done with it.
Try that and see if this fixes your problem.
On Tuesday, May 20, 2014 3:07:21 PM UTC-4, Sheng-Dean wrote:
>
> I am implementing Gaussian blurring using the ScriptIntrinsicBlur class.
> However, I have faced an intermittent issue where sometimes
> ScriptIntrinsicBlur.create() throws RSRuntimeException: Internal error:
> Object id 0.
>
> Here is the most stacktrace that I can post:
>
> android.renderscript.RSRuntimeException: Internal error: Object id 0.
>
>
> at android.renderscript.BaseObj.getID(BaseObj.java:57)
>
>
> at android.renderscript.Script.setVar(Script.java:202)
>
>
> at
> android.renderscript.ScriptIntrinsicBlur.setRadius(ScriptIntrinsicBlur.java:80)
>
>
> at
> android.renderscript.ScriptIntrinsicBlur.create(ScriptIntrinsicBlur.java:54)
>
>
> The bitmap that is being blurred is usually around 300*300 ~ 400*400
> pixels and the blurRadius is set to 20.
>
> private static Bitmap blurBitmap(Context context, Bitmap bm, float
> blurRadius) {
> if (context == null || bm == null || blurRadius < 0) {
> return null;
> }
>
> try {
> /* Make image width a multiple of 4. This is to avoid a bug in
> the
> * implementation of ScriptIntrinsicBlur that causes visual
> * artifacts Source:
> * https://plus.google.com/+RomanNurik/posts/TLkVQC3M6jW */
> if (bm.getWidth() % 4 != 0) {
> bm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth() -
> (bm.getWidth() % 4), bm.getHeight());
> }
>
> final RenderScript rs = RenderScript.create(context);
> final Allocation input = Allocation.createFromBitmap(rs, bm,
> Allocation.MipmapControl.MIPMAP_NONE,
>
> Allocation.USAGE_SCRIPT);
> final Allocation output = Allocation.createTyped(rs,
> input.getType());
> final ScriptIntrinsicBlur script =
> ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
>
> script.setRadius(blurRadius);
> script.setInput(input);
> script.forEach(output);
> output.copyTo(bm);
>
> } catch (RSRuntimeException e) {
> /* Throws android.renderscript.RSRuntimeException: Internal
> error:
> * Object id 0. */
> }
> return bm;
> }
>
> The exception is being thrown when create() is being called. I traced the
> ScriptIntrinsicBlur.create() method and it am guessing that my problem
> starts here:
>
> int id = rs.nScriptIntrinsicCreate(5, e.getID(rs));
> ScriptIntrinsicBlur sib = new ScriptIntrinsicBlur(id, rs);
> sib.setRadius(5.f);
>
> I am guessing that the native method nScriptIntrinsicCreate() may be
> returning 0, which is passed to the constructor, then when setRadius() is
> called it does a check and throws the exception. My questions are:
> 1. What does nScriptIntrinsicCreate() do and what can cause
> nScriptIntrinsicCreate() to return 0?
> 2. How do you go about debugging native methods?
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.