0

I saw a lot of the following error messages in the logcat output of my app:

E/RenderScript: rsAssert failed: mSysRefCount > 0, in frameworks/rs/rsObjectBase.cpp at 147

Despite of this the app did mostly work but sometimes it would crash with SIGSEGV after starting the RenderScript code for a couple of times.

I was able to track down the problem (well, I think). I had a function in my renderscript code that returned an rs_allocation and was defined and used somewhat like this:

rs_allocation gTmp1;
rs_allocation gTmp2;

static rs_allocation blur(float size) {
    if (some_criterion())
        return gTmp1;
    else
        return gTmp2;
}

...
rs_allocation tmp = blur(size);

After changing the function definition to the following the error message went away and the app has not crashed since:

static bool blur(float size) {
    if (some_criterion())
        return false;
    else
        return true;
}

...
bool blurred = blur(size);
rs_allocation tmp = blurred ? gTmp2 : gTmp1;

Now the question is, why does this make any difference? After all rs_allocation is defined just as an int pointer in rs_types.rsh. So nothing too fancy should be happening when a function returns an rs_allocation, right?

devconsole
  • 7,875
  • 1
  • 34
  • 42
  • Seems that something is wrong with the ref-counting for global rs objects. Could you share the build setup and the devices you were using when the error happened? – Miao Wang Nov 15 '16 at 22:26
  • @MiaoWang, my primary test device is a Nexus 5, Android 6.0.1. I've also got a crash report from an LG G4 (p1), Android 6.0, in the Developer Console. Build setup is targetSdkVersion 18, not using the support library, anything else you need? – devconsole Nov 18 '16 at 08:41
  • Last line of SIGSEGV backtrace is "#02 pc 00000594 /data/data/com.my.app/code_cache/com.android.renderscript.cachelibrs.digit_normalize#SW0fAC.so (deleted)". The "deleted" part might be interesting. Let me know if you need more. – devconsole Nov 18 '16 at 08:43

0 Answers0