# E/RSMessageThread: rsInvalidElement: invalid element at libs/renderscript/rsCpuCore.c:1234

- **ID:** `android/renderscript-rsinvalid-element`
- **Domain:** android
- **Category:** runtime_error
- **Error Code:** `rsInvalidElement`
- **Verification:** ai_generated
- **Fix Rate:** 86%

## Root Cause

RenderScript kernel uses an Element type that is not supported or mismatched with allocation data type.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Android 12 (API 31) | active | — | — |
| Android 13 (API 33) | active | — | — |
| RenderScript 24.0 | active | — | — |

## Workarounds

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);** (90% success)
   ```
   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.** (80% success)
   ```
   Migrate from RenderScript to Android NDK or Vulkan Compute for better support. Rewrite kernels in C++ or GLSL.
   ```

## Dead Ends

- **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% fail)
- **Use deprecated rsGetElementAt() instead of rsGetElementAt_type()** — Deprecated in API 23+; still compiles but may cause undefined behavior or slower performance. (65% fail)
