OptiX 7 fail to build GAS when having sbtIndexOffsetBuffer

I need to build a GAS with a single build input (triangle array) and several SBT records.

My test code is list in the following and I get OPTIX_ERROR_INVALID_VALUE when calling optixAccelComputeMemoryUsage():

OptixBuildInput triangleInput = {};
// some settings for triangleInput...(not shown here)
CUdeviceptr temp;
TArray<uint8> testArrays;
CUDA_CHECK(cudaMalloc(reinterpret_cast<void**>(&temp), triangleInput.triangleArray.numIndexTriplets * sizeof(uint8)));
CUDA_CHECK(cudaMemset(reinterpret_cast<void*>(temp), 0, triangleInput.triangleArray.numIndexTriplets * sizeof(uint8)));
triangleInput.triangleArray.numSbtRecords = 2;
triangleInput.triangleArray.sbtIndexOffsetBuffer = temp;
triangleInput.triangleArray.sbtIndexOffsetSizeInBytes = sizeof(uint8);
triangleInput.triangleArray.sbtIndexOffsetStrideInBytes = sizeof(uint8);

OptixAccelBufferSizes gasBufferSizes;
OPTIX_CHECK(optixAccelComputeMemoryUsage(m_context, &accelOptions, &triangleInput, 1, &gasBufferSizes));

However, it works if I set the numSbtRecoeds to 1:

OptixBuildInput triangleInput = {};
// some settings for triangleInput...(not shown here)
triangleInput.triangleArray.numSbtRecords = 1;

OptixAccelBufferSizes gasBufferSizes;
OPTIX_CHECK(optixAccelComputeMemoryUsage(m_context, &accelOptions, &triangleInput, 1, &gasBufferSizes));

Where is the problem?

Sorry, it’s my fault that I didn’t match the size of flags to numSbtRecords.

// some settings for triangleInput…(not shown here)

That would have been the important part to be able to see what you actually did.
I would guess you didn’t provide a sufficiently large flags array to triangleInput.triangleArray.flags?

/// Array of flags, to specify flags per sbt record,
/// combinations of OptixGeometryFlags describing the
/// primitive behavior, size must match numSbtRecords
const unsigned int* flags;

If you set a logger callback inside the OptixDeviceContextOptions and set its logCallbackLevel = 4 and things didn’t crash while accessing an array out of bounds, it should have complained about the build input flags[1] value in debug mode.

EDIT: You beat me to it.