【问题标题】:Renderscript Allocation CrashesRenderscript 分配崩溃
【发布时间】:2014-09-26 01:59:06
【问题描述】:

无法理解,因为当我尝试将分配同时用作输入和输出时,程序崩溃了。

我已经检查过是否由于 android 清单中的某种类型的权限,但都没有。

project.properties如下:

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

代码如下:

...
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);

...

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

非常感谢!!

【问题讨论】:

    标签: android c++ renderscript


    【解决方案1】:

    删除线:

    options.inJustDecodeBounds = true

    这是使用位图的大小信息设置BitmapFactory,但decodeResource() 方法实际上返回null,因为没有为支持像素分配内存,所以没有Bitmap 对象。您需要有背景像素才能实际创建 Allocation,以便它可以在 Java 和 RenderScript 之间编组数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-14
      • 2021-12-31
      • 1970-01-01
      • 2015-04-18
      • 2016-10-09
      相关资源
      最近更新 更多