There is some mysterious problem with creating ScriptC object while using RenderScript. Here's my code:
public class RenderScriptActivity {
private RenderScript mRS;
private ScriptC_kernel mScript = null;
private Allocation m1Allocation, m2Allocation,
m3Allocation, m4Allocation;
private Bitmap mBitmap;
private ImageView mView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_renderscript);
mView = (ImageView) findViewById(R.id.image_view);
}
@Override
protected void onResume() {
super.onResume();
initRenderScript();
}
@Override
protected void onPause() {
super.onPause();
releaseRenderScript();
}
private void initRenderScript() {
mRS = RenderScript.create(this);
int size = 320*240;
m1Allocation = Allocation.createSized(mRS, Element.I16(mRS), size);
m2Allocation = Allocation.createSized(mRS, Element.I16_4(mRS), size);
m3Allocation = Allocation.createSized(mRS, Element.I16_4(mRS), size);
mBitmap = Bitmap.createBitmap(1280, 720, Bitmap.Config.ARGB_8888);
m4Allocation = Allocation.createFromBitmap(mRS, mBitmap);
mScript = new ScriptC_kernel(mRS, getResources(), R.raw.kernel);
}
private void releaseRenderScript() {
m1Allocation.destroy();
m2Allocation.destroy();
m3Allocation.destroy();
m4Allocation.destroy();
// mScript.destroy();
mRS.finish();
}
}
And my kernel (yes, it is empty):
#pragma version(1)
#pragma rs java_package_name(com.example.android.myrenderscript)
The problem is, that after 3rd invocation of initRenderScript()
function (i.e. resuming app, pausing, resuming, pausing and resuming again), my application crashes (SIGSEV) with error:
backtrace:
#00 pc 00027034 /system/lib/libRS.so (android::renderscript::rsrClearObject(android::renderscript::Context const*, android::renderscript::ObjectBase**)+3)
#01 pc 00012c3b /system/lib/libRSDriver.so
#02 pc 00000668 <unknown>
Additionally, if I use mScript.destory()
method (which is commented above), my application crashes right after first invocation of initRenderScript()
. On top of that, if I just comment line, which creates ScriptC_kernel
object, everyting works fine. That's why I suppose, it is problem with creating ScriptC
object.
Is there a chance, anybody knows why this problem occurs?
What is curious here, that problem happens only if I build application from command line (with ant debug
command, Ubuntu 14.04). When I build it with Android Studio or Eclipse, everything works fine.
I should also mention, that in fact not application itself crashes (it contains handful of activities), but one thread, that I suppose is RenderScript's. After the crash, previous activity is brought to foreground again.
I'd greatly appreciate any help, and thanks in advance