Skip to content

ChainedScanDecoupledLookbackDecoupledFallback in Unity package throws AssertionException if size is exactly maxElements #18

@minghinshi

Description

@minghinshi

Example code that produces the bug:

ComputeBuffer tempBuffer0 = null;
ComputeBuffer tempBuffer1 = null;

// 4 elements
ComputeBuffer prefixSumIn = new(1, 16);
ComputeBuffer prefixSumOut = new(1, 16);

ComputeShader compute = [code that gets compute shader];
ChainedScanDecoupledLookbackDecoupledFallback prefixSum = new(compute, 4, ref tempBuffer0, ref tempBuffer1);
prefixSum.PrefixSumInclusive(4, prefixSumIn, prefixSumOut, tempBuffer0, tempBuffer1);

This throws AssertionException from line 127 in ChainedScanDecoupledLookbackDecoupledFallback.

Assert.IsTrue(
m_isValid &&
IsAligned(prefixSumIn.stride) &&
IsAligned(prefixSumOut.stride) &&
size < m_allocatedSize &&
size > k_minSize);

I believe this is caused by the size being equal to the maxElements parameter in the constructor of ChainedScanDecoupledLookbackDecoupledFallback. In the constructor, m_allocatedSize is set to 4...

When PrefixSumInclusive is called, the check in line 131 fails (4 < 4 is false), so an exception is raised.

But I expected maxElements to really be the maximum number of elements. If the input size is 4, the code will run. If the size is 5, it throws an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions