# E/RSMessageThread: rsInvalidElement: 无效元素位于 libs/renderscript/rsCpuCore.c:1234

- **ID:** `android/renderscript-rsinvalid-element`
- **领域:** android
- **类别:** runtime_error
- **错误码:** `rsInvalidElement`
- **验证级别:** ai_generated
- **修复率:** 86%

## 根因

RenderScript 内核使用了不受支持的 Element 类型，或与分配数据类型不匹配。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Android 12 (API 31) | active | — | — |
| Android 13 (API 33) | active | — | — |
| RenderScript 24.0 | active | — | — |

## 解决方案

1. ```
   Ensure Element type in .rs kernel matches Allocation type in Java. Example: In Java, Allocation.createTyped(rs, Type.createXY(rs, Element.F32(rs), w, h)). In .rs, use float *input = rsGetElementAt_type(inputAlloc, x, y);
   ```
2. ```
   Migrate from RenderScript to Android NDK or Vulkan Compute for better support. Rewrite kernels in C++ or GLSL.
   ```

## 无效尝试

- **Change all Element types to F32 in the .rs file** — If allocation data is not float, conversion fails silently; may cause wrong results or crashes. (70% 失败率)
- **Use deprecated rsGetElementAt() instead of rsGetElementAt_type()** — Deprecated in API 23+; still compiles but may cause undefined behavior or slower performance. (65% 失败率)
