Question

This is my constructor of class RSBaseFilterEngine, and my program will create many instance of this class in different activity.

public RSBaseFilterEngine(Context context) {
    rs = RenderScript.create(context);
    this.context = context;
    script = new ScriptC_BaseFilter(rs);
}

The problem is, if I get the instrance of this class more than 1 times, program will crash. The crash will occur when program is processing

script = new ScriptC_BaseFilter(rs);

And, the error log is

Caused by: android.support.v8.renderscript.RSRuntimeException: Loading of ScriptC script failed.
at android.support.v8.renderscript.ScriptC.<init>(ScriptC.java:69)
at com.xxxxxxxxxxx.xxxxxxxx.algorithms.filter.ScriptC_BaseFilter.<init>(ScriptC_BaseFilter.java:41)
at com.xxxxxxxxxxx.xxxxxxxx.algorithms.filter.ScriptC_BaseFilter.<init>(ScriptC_BaseFilter.java:35)
at com.xxxxxxxxxxx.xxxxxxxx.algorithms.RSBaseFilterEngine.<init>(RSBaseFilterEngine.java:33)

Why ScriptC_BaseFilter can't be created twice? Then, I changed code like this

public RSBaseFilterEngine(Context context) {
    rs = RenderScript.create(context);
    this.context = context;
    script = new ScriptC_BaseFilter(rs);
    script.destroy();
    script = new ScriptC_BaseFilter(rs);
}

As I expected, it crashed when program invoked this constructor in the first time.

So, can anyone tell me why this hanppened? Whether there is some details I do not notice?Thanks.


Ok, I will post entire logcat

01-28 10:50:58.637: E/RenderScript(26067): Could not create symlink /data/data/com.xxxxxxxxxxx.xxxxxxxx.algorithms.demo/cache/com.android.renderscript.cache/librs.basefilter#93xfAC.so -> /data/data/com.xxxxxxxxxxx.xxxxxxxx.algorithms.demo//lib/librs.basefilter.so
01-28 10:50:58.637: E/RenderScript(26067): Unable to open shared library (/data/data/com.xxxxxxxxxxx.xxxxxxxx.algorithms.demo//lib/librs.basefilter.so): Symbol not found: load_library[1096]: Library '/system/lib/egl/libGLESv2S3D_adreno200.so' not found
01-28 10:50:58.657: E/RenderScript(26067): Unable to open system shared library (/system/lib/librs.basefilter.so): (null)
01-28 10:50:58.657: D/AndroidRuntime(26067): Shutting down VM
01-28 10:50:58.657: W/dalvikvm(26067): threadid=1: thread exiting with uncaught exception (group=0x40ad5228)
01-28 10:50:58.727: E/AndroidRuntime(26067): FATAL EXCEPTION: main
01-28 10:50:58.727: E/AndroidRuntime(26067): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxxxxxxxxxx.xxxxxxxx.algorithms.demo/com.xxxxxxxxxxx.xxxxxxxx.algorithms.demo.EffectActivity}: android.support.v8.renderscript.RSRuntimeException: Loading of ScriptC script failed.
01-28 10:50:58.727: E/AndroidRuntime(26067):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2194)
01-28 10:50:58.727: E/AndroidRuntime(26067):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2229)
01-28 10:50:58.727: E/AndroidRuntime(26067):    at android.app.ActivityThread.access$600(ActivityThread.java:139)
01-28 10:50:58.727: E/AndroidRuntime(26067):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261)
01-28 10:50:58.727: E/AndroidRuntime(26067):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-28 10:50:58.727: E/AndroidRuntime(26067):    at android.os.Looper.loop(Looper.java:154)
01-28 10:50:58.727: E/AndroidRuntime(26067):    at android.app.ActivityThread.main(ActivityThread.java:4945)
01-28 10:50:58.727: E/AndroidRuntime(26067):    at java.lang.reflect.Method.invokeNative(Native Method)
01-28 10:50:58.727: E/AndroidRuntime(26067):    at java.lang.reflect.Method.invoke(Method.java:511)
01-28 10:50:58.727: E/AndroidRuntime(26067):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-28 10:50:58.727: E/AndroidRuntime(26067):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-28 10:50:58.727: E/AndroidRuntime(26067):    at dalvik.system.NativeStart.main(Native Method)
01-28 10:50:58.727: E/AndroidRuntime(26067): Caused by: android.support.v8.renderscript.RSRuntimeException: Loading of ScriptC script failed.
01-28 10:50:58.727: E/AndroidRuntime(26067):    at android.support.v8.renderscript.ScriptC.<init>(ScriptC.java:69)
01-28 10:50:58.727: E/AndroidRuntime(26067):    at com.xxxxxxxxxxx.xxxxxxxx.algorithms.filter.ScriptC_BaseFilter.<init>(ScriptC_BaseFilter.java:41)
01-28 10:50:58.727: E/AndroidRuntime(26067):    at com.xxxxxxxxxxx.xxxxxxxx.algorithms.filter.ScriptC_BaseFilter.<init>(ScriptC_BaseFilter.java:35)
01-28 10:50:58.727: E/AndroidRuntime(26067):    at com.xxxxxxxxxxx.xxxxxxxx.algorithms.RSBaseFilterEngine.<init>(RSBaseFilterEngine.java:64)
01-28 10:50:58.727: E/AndroidRuntime(26067):    at com.xxxxxxxxxxx.xxxxxxxx.algorithms.RSBaseFilterEngine.getInstance(RSBaseFilterEngine.java:75)
01-28 10:50:58.727: E/AndroidRuntime(26067):    at com.xxxxxxxxxxx.xxxxxxxx.algorithms.demo.EffectActivity.onCreate(EffectActivity.java:87)
01-28 10:50:58.727: E/AndroidRuntime(26067):    at android.app.Activity.performCreate(Activity.java:4531)
01-28 10:50:58.727: E/AndroidRuntime(26067):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
01-28 10:50:58.727: E/AndroidRuntime(26067):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2150)
01-28 10:50:58.727: E/AndroidRuntime(26067):    ... 11 more

I will post some test I made recently.

The following segments of code will make the program crash, the common point is they try to create the same script twice:

rs = RenderScript.create(context);
script = new ScriptC_BaseFilter(rs);
rs.destroy(); // same problem occurred after changed this line to rs.finish() 
rs = RenderScript.create(context);
script = new ScriptC_BaseFilter(rs);

// create same script using different renderscript context will not help
// do rs and rs_base use the same context?
rs = RenderScript.create(context);
rs_base = RenderScript.create(context);
script = new ScriptC_BaseFilter(rs);
script_base = new ScriptC_BaseFilter(rs_base);
Was it helpful?

Solution 2

My colleague find a solution to solve this problem.

First, you should make sure that these code must be added in the file "project.properties"

#------ RenderScript Configuration -------
renderscript.target=18

renderscript.support.mode=true

sdk.buildtools=18.1.0

#------ RenderScript Configuration -------

Then, replace the file "libbcc.dll" in your sdk/build-tools/18.1.0 with a bigger one (the size of the original file is less than 1M, the correct one is 5.1M).

You can download in this website https://code.google.com/p/android/issues/detail?id=60327&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&start=200

OTHER TIPS

Can you check with the following? rs.finish flushes all outstanding commands in renderscript

rs = RenderScript.create(context);
this.context = context;
script = new ScriptC_BaseFilter(rs);
script.destroy();
rs.finish(); //ADD THIS LINE IN YOUR CODE 
script = new ScriptC_BaseFilter(rs);

Is com.xxxxxxxxxxx.xxxxxxxx.algorithms.demo the actual name of the project that you put in your .rs file pragmas? This must match exactly, or you won't be able to load the .bc/.so files.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top