简体   繁体   English

渲染脚本分配崩溃

[英]Renderscript Allocation Crashes

Can not understand because when I try to use the Allocation both as input and ouput, the program crashes. 无法理解,因为当我尝试同时使用Allocation作为输入和输出时,程序崩溃。

I've checked if due to some type of permission in the android manifest, but neither. 我已经检查了是否由于android清单中的某种类型的权限,但是都没有。

The project.properties is as follows: project.properties如下:

target=android-19
android.library.reference.1=../appcompat_v7
renderscript.target=19
renderscript.support.mode=true
sdk.buildtools=20.0.0

The code is as follows: 代码如下:

...
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main);

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    options.inJustDecodeBounds = true;
    Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

    Allocation inputAlloc = Allocation.createFromBitmap(r, bmp, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);

...

And the logcat shows me the following errors: logcat向我显示以下错误:

09-25 11:32:08.623: E/AndroidRuntime(537): FATAL EXCEPTION: main
09-25 11:32:08.623: E/AndroidRuntime(537): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gpurenderscript/com.example.gpurenderscript.MainActivity}: java.lang.NullPointerException
09-25 11:32:08.623: E/AndroidRuntime(537):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
09-25 11:32:08.623: E/AndroidRuntime(537):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-25 11:32:08.623: E/AndroidRuntime(537):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-25 11:32:08.623: E/AndroidRuntime(537):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-25 11:32:08.623: E/AndroidRuntime(537):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-25 11:32:08.623: E/AndroidRuntime(537):  at android.os.Looper.loop(Looper.java:123)
09-25 11:32:08.623: E/AndroidRuntime(537):  at android.app.ActivityThread.main(ActivityThread.java:3683)
09-25 11:32:08.623: E/AndroidRuntime(537):  at java.lang.reflect.Method.invokeNative(Native Method)
09-25 11:32:08.623: E/AndroidRuntime(537):  at java.lang.reflect.Method.invoke(Method.java:507)
09-25 11:32:08.623: E/AndroidRuntime(537):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-25 11:32:08.623: E/AndroidRuntime(537):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-25 11:32:08.623: E/AndroidRuntime(537):  at dalvik.system.NativeStart.main(Native Method)
09-25 11:32:08.623: E/AndroidRuntime(537): Caused by: java.lang.NullPointerException
09-25 11:32:08.623: E/AndroidRuntime(537):  at android.support.v8.renderscript.Allocation.createFromBitmap(Allocation.java:1337)
09-25 11:32:08.623: E/AndroidRuntime(537):  at android.support.v8.renderscript.Allocation.createFromBitmap(Allocation.java:1388)
09-25 11:32:08.623: E/AndroidRuntime(537):  at com.example.gpurenderscript.MainActivity.onCreate(MainActivity.java:33)
09-25 11:32:08.623: E/AndroidRuntime(537):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-25 11:32:08.623: E/AndroidRuntime(537):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
09-25 11:32:08.623: E/AndroidRuntime(537):  ... 11 more

Thanks a lot!! 非常感谢!!

Remove the line: 删除行:

options.inJustDecodeBounds = true

This is setting up the BitmapFactory with the sizing information for your bitmap, but the decodeResource() method is actually return null as there was no memory allocated for the backing pixels, so no Bitmap object. 这是使用您的位图的大小信息来设置BitmapFactory的,但是由于没有为后备像素分配内存,因此没有Bitmap对象, decodeResource()方法实际上返回null。 You need to have the backing pixels in order for the Allocation to actually be created so it can marshall the data between Java and RenderScript. 您需要具有后备像素,才能真正创建Allocation ,以便可以将Java和RenderScript之间的数据编组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM