I call this method two consecutive times because I needed a blur radius of 40px, but the SDK limitation was only 25px, so I thought I would just blur it twice with 20px.
On Fri, May 23, 2014 at 1:18 PM, Harri Smatt <har...@gmail.com> wrote: > Hi, > > How frequently do you call this method? I mean, you re-create both > RenderScript and IntrinsicBlur objects on every call. And I am wondering > how the underlying native implementation copes with this if the method is > called twice or more within short a period. > > -- > H > On May 20, 2014 10:08 PM, "littledot" <littledot5...@gmail.com> 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 android-developers@googlegroups.com >> To unsubscribe from this group, send email to >> android-developers+unsubscr...@googlegroups.com >> 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 android-developers+unsubscr...@googlegroups.com. >> >> For more options, visit https://groups.google.com/d/optout. >> > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > 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 a topic in the > Google Groups "Android Developers" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/android-developers/kGxHq3bcBdc/unsubscribe > . > To unsubscribe from this group and all its topics, send an email to > android-developers+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Thank you for your time. Yours truly, Sheng-Dean Chang 章聖典 (s39ch...@uwaterloo.ca, littledot5...@gmail.com) -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com 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 android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.