# FATAL EXCEPTION: RSMessageThread. Error: rsInvalidElement: invalid element at libs/renderscript/rsCpuCore.c:1234

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

## Root Cause

RenderScript allocation or kernel operation uses an incorrectly defined or mismatched Element type, often due to mixing float and int types in script or passing wrong allocation to forEach.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Android 8.0 (API 26) | active | — | — |
| Android 10 (API 29) | active | — | — |
| Android 12 (API 31) | active | — | — |

## Workarounds

1. **In your .rs script, ensure all allocations use matching Element types. For example, if passing a float allocation, define the kernel with `__attribute__((kernel)) void root(const float *v_in, float *v_out)` and create the allocation with `Element.F32(rs)`. Do not mix int and float.** (85% success)
   ```
   In your .rs script, ensure all allocations use matching Element types. For example, if passing a float allocation, define the kernel with `__attribute__((kernel)) void root(const float *v_in, float *v_out)` and create the allocation with `Element.F32(rs)`. Do not mix int and float.
   ```
2. **Replace RenderScript with Android's NDK or custom C++ code using `android::renderscript::RS` API, and validate Element creation with `rsCreateElement()` using correct data type enum (e.g., `RS_TYPE_FLOAT_32`).** (80% success)
   ```
   Replace RenderScript with Android's NDK or custom C++ code using `android::renderscript::RS` API, and validate Element creation with `rsCreateElement()` using correct data type enum (e.g., `RS_TYPE_FLOAT_32`).
   ```

## Dead Ends

- **** — The error is not a runtime state issue but a script or allocation definition bug; clearing cache does not fix incorrect Element types. (95% fail)
- **** — The error occurs regardless of SDK version if the Element definition in the script is invalid; changing minSdkVersion does not correct the script logic. (90% fail)
