Hi Harri,

Thanks so much for your input! I will surely try that!

It was extremely hard for me to debug this issue because the the exception
was intermittent even when I called it two times in a row, it only happened
twice and I could never reproduce it again, so for me, it was rather hard
to test.

I am curious and at awe at your over-the-air support, how did you know I
was calling it more than once?

Thanks again!


On Mon, May 26, 2014 at 9:21 AM, Harri Smatt <[email protected]> wrote:

> Hello,
>
> In that case it *might* help if you create RS context and script intrinsic
> blur *only once* and call invoke as many times you need to.
>
> If recreating RS context and/script is the cause, it is something you
> could test rather easily since the crash would happen on second call to
> your blur method.
>
> --
> H
> On May 25, 2014 10:43 AM, "Chang Sheng-Dean 章聖典" <[email protected]>
> wrote:
>
>> 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 <[email protected]> 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" <[email protected]> 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.
>>>>
>>>  --
>>> 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 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
>>> [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Thank you for your time.
>>
>> Yours truly,
>> Sheng-Dean Chang 章聖典
>> ([email protected], [email protected])
>>
>> --
>> 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.
>>
>  --
> 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 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
> [email protected].
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Thank you for your time.

Yours truly,
Sheng-Dean Chang 章聖典
([email protected], [email protected])

-- 
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.

Reply via email to