# Optix throws error in the setAnyHitProgram method in material

**URL:** <https://forums.developer.nvidia.com/t/optix-throws-error-in-the-setanyhitprogram-method-in-material/64962>\
**Category:** OptiX\
**Created:** [September 11, 2018, 4:46am UTC](https://forums.developer.nvidia.com/t/optix-throws-error-in-the-setanyhitprogram-method-in-material/64962 "2018-09-11T04:46:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sfrankricharrd](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@sfrankricharrd](https://forums.developer.nvidia.com/u/sfrankricharrd)\
**Post date:** [September 11, 2018, 4:46am UTC](https://forums.developer.nvidia.com/t/optix-throws-error-in-the-setanyhitprogram-method-in-material/64962/1 "2018-09-11T04:46:26Z")

</div>

In the optix sample,  
optixmesh.cpp  
method name - optix::Material createOptiXMaterial

mat-\>setAnyHitProgram(1u, any\_hit ); this line throws the below error

“Invalid value (Details: Function “\_rtMaterialSetAnyHitProgram” caught exception: Invalid ray type index: 1)”

can someone please help with this?

---

<div class="post-metadata">

**Author:** ![droettger](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/droettger/32/14043_2.png) [@droettger](https://forums.developer.nvidia.com/u/droettger)\
**Post date:** [September 12, 2018, 9:36am UTC](https://forums.developer.nvidia.com/t/optix-throws-error-in-the-setanyhitprogram-method-in-material/64962/2 "2018-09-12T09:36:23Z")

</div>

That would happen if there hasn’t been an rtContextSetRayTypeCount function call with a value of 2 or more before.  
Please step through your code and see if there had been a sufficiently large raytype count set before that call.

OptiX API reference docs about those calls:  
[url][http://raytracing-docs.nvidia.com/optix/api/html/group\_\_\_context.html#ga40880c075df428b0819270e340507943[/url]](http://raytracing-docs.nvidia.com/optix/api/html/group___context.html#ga40880c075df428b0819270e340507943%5B/url%5D)  
[url][http://raytracing-docs.nvidia.com/optix/api/html/group\_\_\_material.html#ga0f0377c963b834ca84ff95ce4886b0c3[/url]](http://raytracing-docs.nvidia.com/optix/api/html/group___material.html#ga0f0377c963b834ca84ff95ce4886b0c3%5B/url%5D)

---

<div class="post-metadata">

**Author:** ![TomNVIDIA](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/tomnvidia/32/14181_2.png) [@TomNVIDIA](https://forums.developer.nvidia.com/u/TomNVIDIA)\
**Post date:** [June 14, 2022, 9:06pm UTC](https://forums.developer.nvidia.com/t/optix-throws-error-in-the-setanyhitprogram-method-in-material/64962/3 "2022-06-14T21:06:08Z")

</div>

Closed on June 14, 2022, 9:06pm UTC


