[Solved]Assertion failed: tex->getAccess( deviceIndex ).getKind() == MAccess::NONE

My rendering program works fine using OptiX3.9.1 + VS2013 + CUDA7.0 + Window7/Window10, when I update to VS2017 + OptiX5.1 + CUDA 9.2 + Window10, I get the following errors printed in the console(rendering succeeded for 16 times and began to fail at 17th time):

Render 1:
Succeeded

Render 2:
Succeeded

...

Render 16:
Succeeded

Render 17:
c:\users\win10-c\desktop\usrender\src\usrender\usrenderoptixrender.cpp(69) : error: Unknown error (Details: Function "_rtContextLaunch2D" caught exception: Assertion failed: "tex->getAccess( deviceIndex ).getKind() == MAccess::NONE", file: C:\u\workspace\rel5.1-win64-cuda90-VS2015-build-Release\sw\wsapps\raytracing\rtsdk\rel5.1\src\Memory\MemoryManager.cpp, line: 2166)

Render 18:
c:\users\win10-c\desktop\usrender\src\usrender\usrenderoptixrender.cpp(69) : error: Unknown error (Details: Function "_rtContextLaunch2D" caught exception: Assertion failed: "!m_enteredFromAPI : Memory manager already entered from API", file: C:\u\workspace\rel5.1-win64-cuda90-VS2015-build-Release\sw\wsapps\raytracing\rtsdk\rel5.1\src\Memory\MemoryManager.cpp, line: 963)

Render 19:
c:\users\win10-c\desktop\usrender\src\usrender\usrenderoptixrender.cpp(69) : error: Unknown error (Details: Function "_rtContextLaunch2D" caught exception: Assertion failed: "!m_enteredFromAPI : Memory manager already entered from API", file: C:\u\workspace\rel5.1-win64-cuda90-VS2015-build-Release\sw\wsapps\raytracing\rtsdk\rel5.1\src\Memory\MemoryManager.cpp, line: 963)

...

It seems something goes wrong with the textures, because when I do the renderings without textures they all succeed. Does someone know how to fix it?

Thanks.

Try to replace texturesamplers and tex2D(…) with texture ids and optix::rtTex2D(…)
See more:
[url]https://devtalk.nvidia.com/default/topic/1033091/optix/cubesampler-from-cubebuffer/post/5256494/#5256494[/url]

In VS2017 also try toolset v140 (of VS2015) instead of toolset v141. And try CUDA 9.0 instead of CUDA 9.2, cause OptiX 5.1.0 was built with that version, see: [url]https://devtalk.nvidia.com/default/topic/1036401/optix/optix-installation-windows-cuda-9-2/post/5265364/#5265364[/url]

Thanks for the reply.

The optix::rtTex2D(…) is used in my code, and I tried toolset v140 (of VS2015) and CUDA 9.0, the same error occured.

Here is some more new information after I tried different methods:

Original codes:
//create some textures (marked as texture group A)
//do rendering(call context_->launch(ENTRY_POINT_PINHOLE, width, height) using textures from group A
//succeed

//create some more textures (marked as texture group B)
//at now textures from group A still live in GPU
//do rendering(call context_->launch(ENTRY_POINT_PINHOLE, width, height)) using textures from group B
//succeed

//create some more textures (marked as texture group C)
//at now textures from group A and B still live in GPU
//do rendering(call context_->launch(ENTRY_POINT_PINHOLE, width, height)) using textures from group C
//succeed

//create some more textures (marked as texture group D)
//at now textures from group A, B and C still live in GPU
//do rendering(call context_->launch(ENTRY_POINT_PINHOLE, width, height)) using textures from group D
//succeed

//########
//no more textures created
//at now textures from group A, B, C and D still live in GPU
//do rendering(call context_->launch(ENTRY_POINT_PINHOLE, width, height)) using textures from group A
//error occured!!!

//no more textures created
//at now textures from group A, B, C and D still live in GPU
//do rendering(call context_->launch(ENTRY_POINT_PINHOLE, width, height)) using textures from group B
//error occured!!!

...//error kept occuring

RT_PROGRAM void PinholeCamera()
{ 
    OptixSceneParam& scene_param = _SCENE_PARAM;
    //directly set the output result without calling rtTrace
    scene_param.outline_output_buffer_[launch_number] = COLOR_RED;
}

As shown in the above codes, even when the rtTrace(…) function is not called from the PinholeCamera(), the error still occurs.
At first I thought that when I use textures from group A for the second time(where I comment the “########” in the code and when the error begin to occur), maybe these textures from group A get destroyed somewhere accidently. But the thing is that before calling the context_->launch(ENTRY_POINT_PINHOLE, width, height) function I can access these textures from CPU(using map(), unmap()), which means that these textures are still live.
Then I changed the code by adding a texture destroying and recreating process before the context_->launch(ENTRY_POINT_PINHOLE, width, height)) call, no errors occured!!!
Here is the modified code:

Modified codes:
//create some textures (marked as texture group A)
//do rendering(call context_->launch(ENTRY_POINT_PINHOLE, width, height) using textures from group A
//succeed

//destroy all existing textures
//create some more textures (marked as texture group B)
//at now textures from group A are dead
//do rendering(call context_->launch(ENTRY_POINT_PINHOLE, width, height)) using textures from group B
//succeed

//destroy all existing textures
//create some more textures (marked as texture group C)
//at now textures from group A and B are dead
//do rendering(call context_->launch(ENTRY_POINT_PINHOLE, width, height)) using textures from group C
//succeed

//destroy all existing textures
//create some more textures (marked as texture group D)
//at now textures from group A, B and C are dead
//do rendering(call context_->launch(ENTRY_POINT_PINHOLE, width, height)) using textures from group D
//succeed

//destroy all existing textures
//textures from group A are recreated
//at now textures from group B, C and D are dead
//do rendering(call context_->launch(ENTRY_POINT_PINHOLE, width, height)) using textures from group A
//succeed!!!

//destroy all existing textures
//textures from group B are recreated
//at now textures from group A, C and D are dead
//do rendering(call context_->launch(ENTRY_POINT_PINHOLE, width, height)) using textures from group B
//succeed!!!

...//always succeed!!

RT_PROGRAM void PinholeCamera()
{ 
    OptixSceneParam& scene_param = _SCENE_PARAM;
   //call trace
    rtTrace(...)
    scene_param.outline_output_buffer_[launch_number] = prd.result;
}

But such a solution is not what I want because the texture creation costs too much and also I can’t figure out why I need this destroying and recreation process since everything works fine with older tool chains(OptiX3.9.1 + VS2013 + CUDA7.0 + Window7/Window10).

To be able to analyze this we would need a minimal but complete reproducer.
Error messages alone or pseudo code won’t be sufficient.

Here is a way to provide that without the need for the actual application:
https://devtalk.nvidia.com/default/topic/803116/?comment=4436953

If this needs to stay confidential send me a private message either with the OAC archive attached (paper clip icon in the upper right of your submitted posts) or if it’s too big, I can set up a temporary FTP account to exchange files.

You need to differentiate between Buffers and TextureSamplers. They are separate objects. Destroying a TextureSampler does not destroy the attached Buffer.

The problem is solved by regenerating texture samplers after setting parameters for them more than once, with the help of Detlef Roettger, by pointing out to me this OptiX bug:

It’s really lucky to have you guys here answering our questions.