【发布时间】:2014-07-25 01:54:16
【问题描述】:
我已经使用 RenderScript 工作了几天,但我不知道如何正确地将数组从 Java 传递到 RenderScript。我看到了一些示例,但没有一个对我有用,而且我因缺乏文档而陷入困境。
在这段代码中,我试图在 bb 和 coords 数组之间为 root() 接收到的每个索引 in 做一些检查:
渲染脚本代码:
#pragma version(1)
#pragma rs java_package_name(com.me.example)
int4 bb;
rs_allocation coords;
void __attribute__((kernel)) root(int32_t in)
{
int index = in;
if(bb[index] > rsGetElementAt_int(coords, index))
{
if(bb[index + 1] > rsGetElementAt_int(coords, index + 1))
{
//do something
}
}
}
Java 代码:
RenderScript mRS = RenderScript.create(this);
ScriptC_script script = new ScriptC_script(mRS, getResources(), R.raw.match);
// This arrays comes with data from another place
int[] indices;
int[] coords;
// Create allocations
Allocation mIN = Allocation.createSized(mRS, Element.I32(mRS), indices.length);
Allocation mOUT = Allocation.createSized(mRS, Element.I32(mRS), indices.length);
Allocation coordsAlloc = Allocation.createSized(mRS, Element.I32(mRS), coords.length);
// Fill it with data
mIN.copyFrom(indices);
coordsAlloc.copyFrom(coords);
// Set the data array
script.set_coords(coordsAlloc);
// Create bb and run
script.set_bb(new Int4 (x, y, width, height));
script.forEach_root(mIN);
当我执行它时,我在 set_coords() 语句中收到此错误:
Script::setVar 无法设置分配,无效槽索引
然后程序退出:
致命信号 11 (SIGSEGV) 位于 0x00000000 (code=1),线程 12274 ...
【问题讨论】:
标签: android arrays allocation renderscript