RenderScript错误致命信号11和无效RS infor文件

时间:2015-03-08 02:28:54

标签: android renderscript rs

我在android 4.1.2上写了一个RenderScript程序。 Eclipse没有注意到错误,但我无法在虚拟设备上运行此程序(尽管我选择将GPU用于虚拟机)。

这是我的程序

MainActivity.java

package com.gettingstarted;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.renderscript.Allocation;
import android.renderscript.RenderScript;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends Activity {
    private Bitmap mBitmapIn;
    private Bitmap mBitmapOut;
    private RenderScript mRS;
    private Allocation mInAllocation;
    private Allocation mOutAllocation;
    private ScriptC_mono mScript;
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mRS = RenderScript.create(this);
        mBitmapIn = BitmapFactory.decodeResource(getResources(), R.drawable.basic_shapes);

        mInAllocation =  Allocation.createFromBitmap(mRS,  mBitmapIn, 
            Allocation.MipmapControl.MIPMAP_NONE,
            Allocation.USAGE_SCRIPT);
        mOutAllocation = Allocation.createTyped(mRS,mInAllocation.getType());
        Log.i("error", "1");
        mScript = new ScriptC_mono(mRS, getResources(), R.raw.mono);
        Log.i("error", "2");
        mScript.forEach_root(mInAllocation, mOutAllocation);

        mOutAllocation.copyTo(mBitmapOut); 
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
         // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
 }

mono.rs

#pragma version(1)
#pragma rs java_package_name(com.gettingstarted)

#include "rs_math.rsh"

void init() {

}

const static float3 gMonoMult = {0.299f ,  0.587f ,  0.114f};
void root(const uchar4 *v_in, uchar4 *v_out) {
    //unpack a color to a float4
    float4 f4 = rsUnpackColor8888(*v_in);
    float3 mono = dot(f4.rgb,  gMonoMult);
    *v_out = rsPackColorTo8888(mono);
}

ScriptC_mono.java

/*
 * Copyright (C) 2011-2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * This file is auto-generated. DO NOT MODIFY!
 * The source Renderscript file: E:\\Android_project_Renderscript      \\GettingStarted\\src\\com\\gettingstarted\\mono.rs
 */

package com.gettingstarted;

import android.renderscript.*;
import android.content.res.Resources;

/**
* @hide
*/
public class ScriptC_mono extends ScriptC {
    private static final String __rs_resource_name = "mono";
    // Constructor
    public  ScriptC_mono(RenderScript rs) {
        this(rs,
             rs.getApplicationContext().getResources(),
             rs.getApplicationContext().getResources().getIdentifier(
                 __rs_resource_name, "raw",
                 rs.getApplicationContext().getPackageName()));
    }

    public  ScriptC_mono(RenderScript rs, Resources resources, int id) {
         super(rs, resources, id);
        __U8_4 = Element.U8_4(rs);
    }

    private Element __U8_4;
    private final static int mExportForEachIdx_root = 0;
    public void forEach_root(Allocation ain, Allocation aout) {
        // check ain
        if (!ain.getType().getElement().isCompatible(__U8_4)) {
            throw new RSRuntimeException("Type mismatch with U8_4!");
        }
        // check aout
        if (!aout.getType().getElement().isCompatible(__U8_4)) {
            throw new RSRuntimeException("Type mismatch with U8_4!");
        }
        Type t0, t1;        // Verify dimensions
        t0 = ain.getType();
        t1 = aout.getType();
        if ((t0.getCount() != t1.getCount()) ||
            (t0.getX() != t1.getX()) ||
            (t0.getY() != t1.getY()) ||
            (t0.getZ() != t1.getZ()) ||
            (t0.hasFaces()   != t1.hasFaces()) ||
            (t0.hasMipmaps() != t1.hasMipmaps())) {
            throw new RSRuntimeException("Dimension mismatch between parameters ain and aout!");
         }

         forEach(mExportForEachIdx_root, ain, aout, null);
     }

 }

我得到了这样的错误 enter image description here

你能帮我解决这个问题。非常感谢你!

03-07 21:11:20.855: D/dalvikvm(1954): GC_FOR_ALLOC freed 51K, 5% free 2744K/2880K, paused 3ms, total 3ms
03-07 21:11:20.855: I/error(1954): 1
03-07 21:11:20.865: E/bcc(1954): Invalid RS info file /data/data/com.gettingstarted/cache/com.android.renderscript.cache/mono.o.info! (No such file or directory)
03-07 21:11:21.345: A/libc(1954): Fatal signal 11 (SIGSEGV) at 0x0000906d (code=1), thread 1967 (.gettingstarted)
03-07 21:11:25.755: D/dalvikvm(1970): GC_FOR_ALLOC freed 53K, 5% free 2744K/2880K, paused 2ms, total 3ms
03-07 21:11:25.785: I/error(1970): 1
03-07 21:11:25.785: E/bcc(1970): Invalid RS info file /data/data/com.gettingstarted/cache/com.android.renderscript.cache/mono.o.info! (No such file or directory)
03-07 21:11:25.825: A/libc(1970): Fatal signal 11 (SIGSEGV) at 0x0000906d (code=1), thread 1983 (.gettingstarted)
03-07 21:11:26.455: D/dalvikvm(1986): GC_FOR_ALLOC freed 58K, 5% free 2744K/2888K, paused 2ms, total 21ms
03-07 21:11:26.465: I/error(1986): 1
03-07 21:11:26.465: E/bcc(1986): Invalid RS info file /data/data/com.gettingstarted/cache/com.android.renderscript.cache/mono.o.info! (No such file or directory)
03-07 21:11:26.555: A/libc(1986): Fatal signal 11 (SIGSEGV) at 0x0000906d (code=1), thread 2000 (.gettingstarted)

0 个答案:

没有答案