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?