Thor Russell
Thor Russell

Reputation: 129

Cannot get simple renderscript maths function to run

I am trying to get a simple renderscript function to take two numnbers, add them and return the result, however I have not managed to find an example project to do that smoothly. I keep getting a weird error when I try to load the file:

ScriptC_myexamplescript myScript;
RenderScript rs = RenderScript.create(this);

I get the error:

Symbol not found: .rs.dtor  on the next line:
myScript = new ScriptC_myexamplescript(rs, getResources(), R.raw.myexamplescript);

My .rs file is just something simple:

#pragma version(1)
#pragma rs java_package_name(com.exercise.<my pacakge name>);

void init(){

}

void root(const float *v_in, float *v_out) {

   const float *data = v_in;
   float *outData = v_out;
   *outData = *data;    

}

Does anyone know what this means, or if there is a simple project I can download for Android ICS and later that does maths, not actual rendering that just works?

(I can get a rendering script file to work, but that isn't what I want. I don't want any graphics in it)

EDIT Today I have tried to make it run, and get the following problem:

Allocation mInAllocation = null;
Allocation mOutAllocation;

float[] A = new float[1];
for (int i = 0; i < 1; i++) {
A[i] = 2;
}



Allocation inFloatPointer = Allocation.createSized(rs, Element.F32(rs), A.length, Allocation.USAGE_SCRIPT);
Allocation outFloatPointer = Allocation.createSized(rs, Element.F32(rs), A.length, Allocation.USAGE_SCRIPT);  
inFloatPointer.copyFrom(A); // copies from an array of floats (random numbers in this test case).
mScript.forEach_root(inFloatPointer, outFloatPointer);            

I get the error message: the method forEach_root is undedifed for type ScriptC_RenderScript There is no function forEach_root in the .java file and even after I clean the project it still is not there.

Is there a simple project I can download with just a maths function I can download?

Upvotes: 0

Views: 1010

Answers (2)

eternauta3k
eternauta3k

Reputation: 113

Add to the manifest, before <application>, the line

<uses-sdk android:minSdkVersion="14" />

Any value under 14 throws the error you mentioned after ant clean debug

Upvotes: 0

Stephen Hines
Stephen Hines

Reputation: 2622

Are you sure that there is indeed an error here? I believe you are just seeing extra verbose logging information. Can you post the exact logcat (or Java exception trace)? Note that if you actually want to execute your function, you will need to create an input and output allocation and then call "myScript.forEach_root(input, output);" in order to have it execute the root() function on each cell of input/output. When that is done, you can read the results back from the output allocation and use them from Java.

Upvotes: 1

Related Questions