Fix: avatar indices and NRE in FinishAvatarMatricesCalculationSystem #6482
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Description
What does this PR change?
This PR introduces an explicit invariant around the global avatar job index to prevent invalid runtime state from propagating into native rendering code.
A raw
intindex is replaced with a strongly-typed struct (GlobalJobArrayIndex) that encodes validity rules in the type system and enforces them at architectural boundaries. As a result, invalid indices are no longer representable or passable into GPU paths.This is an intentional invariant enforcement, not an ad-hoc guard or defensive workaround.
Problem
The current avatar skinning flow allows invalid state (e.g. negative or uninitialized
indexInGlobalResultArray) to propagate deep into the rendering pipeline without semantic constraints.As a result:
Invalid indices reach
ComputeBuffer.SetData, causing:The same corrupted state may surface as:
Failures are non-deterministic and occur far from the source of the invalid state.
Which exception triggers first is effectively probabilistic.
This is not a single-call bug, but a missing invariant that allows illegal state to exist and flow through the system.
Changes
intwith a domain-specific value type:GlobalJobArrayIndexComputeBuffer.SetDatanever receive invalid indices
This aligns the implementation with an invariant-driven design already used elsewhere in the codebase (e.g.
BoneArray).The scope is limited to enforcing a critical invariant, not reworking the entire data flow.
Summary
Test Instructions
Test Steps
Expected Result
ArgumentOutOfRangeExceptionfromComputeBuffer.SetDataNullReferenceExceptionfrom native compute buffer pathsAdditional Testing Notes
Code Review Reference
[Code Review Standards](https://github.com/decentraland/unity-renderer/blob/master/docs/code-review-standards.md)