Unity-Technologies/UnityCsReference · error · ArgumentException
rendererIDs and results NativeArrays don't match in length.
Error message
rendererIDs and results NativeArrays don't match in length.
What it means
Thrown by the current GetRenderersFilteringResults(ReadOnlySpan<EntityId>, Span<bool>) overload when rendererIDs.Length != results.Length. The native implementation writes one bool per renderer, so the caller must supply a results span of identical length. A length mismatch throws ArgumentException.
Source
Thrown at Editor/Mono/Camera/EditorCameraUtils.bindings.cs:32
namespace UnityEditor.Rendering
{
[NativeHeader("Editor/Src/Camera/EditorCameraUtils.h")]
[RequiredByNativeCode]
public static class EditorCameraUtils
{
public static bool RenderToCubemap(this Camera camera, Texture target, int faceMask, StaticEditorFlags culledFlags)
=> RenderToCubemapImpl(camera, target, faceMask, culledFlags) == 1;
[System.Obsolete("GetRenderersFilteringResults(ReadOnlySpan<int>) is obsolete. Use GetRenderersFilteringResults(ReadOnlySpan<EntityId>) instead.", true)]
public static unsafe void GetRenderersFilteringResults(ReadOnlySpan<int> rendererIDs, Span<bool> results)
{
throw new System.NotImplementedException("GetRenderersFilteringResults(ReadOnlySpan<int>) is obsolete. Use GetRenderersFilteringResults(ReadOnlySpan<EntityId>) instead.");
}
public static unsafe void GetRenderersFilteringResults(ReadOnlySpan<EntityId> rendererIDs, Span<bool> results)
{
if (rendererIDs.Length != results.Length)
throw new ArgumentException("rendererIDs and results NativeArrays don't match in length.");
GetRenderersFilteringResultsImpl(rendererIDs, results);
}
[System.Obsolete("GetRenderersHiddenResultBits(ReadOnlySpan<int>) is obsolete. Use GetRenderersHiddenResultBits(ReadOnlySpan<EntityId>) instead.", true)]
public static unsafe void GetRenderersHiddenResultBits(ReadOnlySpan<int> rendererIDs, Span<ulong> resultBits)
{
throw new System.NotImplementedException("GetRenderersHiddenResultBits(ReadOnlySpan<int>) is obsolete. Use GetRenderersHiddenResultBits(ReadOnlySpan<EntityId>) instead.");
}
public static unsafe void GetRenderersHiddenResultBits(ReadOnlySpan<EntityId> rendererIDs, Span<ulong> resultBits)
{
const int kBitsPerChunkCount = sizeof(ulong) * 8;
int resultBitsLengthExpected = (rendererIDs.Length + kBitsPerChunkCount - 1) / kBitsPerChunkCount;
if (resultBitsLengthExpected != resultBits.Length)
throw new ArgumentException("Unexpected resultBits Span length. The expected length of resultBits Span should be equal to the formula: (rendererIDs.Length + 63) / 64");View on GitHub (pinned to 225b0fbdb5)
Solutions
- Allocate results with the same length as rendererIDs (new bool[rendererIDs.Length] or Span over matching buffer).
- Validate lengths match before calling and resize the results buffer if not.
- Use stackalloc or a pooled buffer sized exactly to rendererIDs.Length.
Example fix
// before var results = new bool[prevCount]; EditorCameraUtils.GetRenderersFilteringResults(ids, results); // after Span<bool> results = ids.Length <= 256 ? stackalloc bool[ids.Length] : new bool[ids.Length]; EditorCameraUtils.GetRenderersFilteringResults(ids, results);
Defensive patterns
Strategy: validation
Validate before calling
if (rendererIDs.Length == results.Length) EditorCameraUtils.GetRenderersFilteringResults(rendererIDs, results);
Type guard
static bool LengthsMatch<T1,T2>(ReadOnlySpan<T1> a, Span<T2> b) => a.Length == b.Length;
Prevention
- Size the results span to exactly rendererIDs.Length.
- Re-allocate buffers when the renderer set size changes.
- Prefer stackalloc sized to the current query.
When it happens
Trigger: Passing a results Span<bool> whose Length differs from the rendererIDs ReadOnlySpan<EntityId> Length — e.g. reusing a pre-sized buffer that does not match the current renderer count.
Common situations: Allocating results once and reusing it across varying renderer sets; off-by-one sizing; pooling buffers without resizing to the new query size.
Related errors
- Platform GUID {platformGuid} is not a valid Unity build plat
- PersistentLocalStorageSize must be between 256 and 4096, but
- Provided GameObject is not a Prefab instance
- Given input object is not a prefab asset
- Object to create variant from has to be a Prefab root
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/ec43bf4c15ed1a67.
Report an issue: GitHub.