dynamic array geometry input problem

About a month ago, I was studied geometry import and run the program. Fortunately, it was successful.
However, I found an issue with an unknown problem.
The problem is:

The first code above also works sometimes.
But of course nothing is displayed on the screen.

OptiX Error: ‘Unknown error (Details: Function “_rtContextLaunch2D” caught exception: Encountered a CUDA error: cudaDriver().CuMemcpy2D( pCopy ) returned (700): Illegal address)’

unsigned int total_faces = 5804;

float2 *tex = new float2[total_faces * 3];
float3 *VTX = new float3[total_faces * 3];
float3 *NVP = new float3[total_faces * 3];
unsigned int *index = new unsigned int[total_faces * 3];

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// after input data....................
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

const unsigned int num_vertices = total_faces*3;
const unsigned int num_faces	= total_faces;

Buffer vertex_buffer = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_FLOAT3, num_vertices);
Buffer normal_buffer = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_FLOAT3, num_vertices);
Buffer texcoord_buffer = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_FLOAT2, num_vertices);
Buffer index_buffer  = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_UNSIGNED_INT3, num_faces);
			
memcpy(vertex_buffer   ->map(), VTX, sizeof(VTX));
memcpy(normal_buffer   ->map(), NVP, sizeof(NVP));
memcpy(texcoord_buffer ->map(), tex, sizeof(tex));
memcpy(index_buffer    ->map(), index, sizeof(index));

vertex_buffer->unmap();
normal_buffer->unmap();
texcoord_buffer->unmap();
index_buffer ->unmap();

whatever good working code (static array)

unsigned int total_faces = 5804;

float2 tex[5804 * 3];
float3 VTX[5804 * 3];
float3 NVP[5804 * 3];
unsigned int index[5804 * 3];

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// after input data....................
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

const unsigned int num_vertices = total_faces*3;
const unsigned int num_faces	= total_faces;

Buffer vertex_buffer = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_FLOAT3, num_vertices);
Buffer normal_buffer = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_FLOAT3, num_vertices);
Buffer texcoord_buffer = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_FLOAT2, num_vertices);
Buffer index_buffer  = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_UNSIGNED_INT3, num_faces);
			
memcpy(vertex_buffer   ->map(), VTX, sizeof(VTX));
memcpy(normal_buffer   ->map(), NVP, sizeof(NVP));
memcpy(texcoord_buffer ->map(), tex, sizeof(tex));
memcpy(index_buffer    ->map(), index, sizeof(index));

vertex_buffer->unmap();
normal_buffer->unmap();
texcoord_buffer->unmap();
index_buffer ->unmap();

I want to do dynamic allocation and I need it.
How should dynamic allocation be done?

That’s a simple error in your C++ code.

With float2 *tex = new float2[total_faces * 3]; sizeof(tex) == 8 because tex is a 64-bit pointer.
With float2 tex[5804 * 3]; sizeof(tex) == sizeof(float2) * 5804 * 3 because tex is an array of float2.
Similar for the other pointers.

You need to calculate the correct byte size of the memory block the pointers are pointing to.
For example: memcpy(texcoord_buffer->map(), tex, sizeof(float2) * num_vertices);
which matches the size of the buffer you created with
Buffer texcoord_buffer = context->createBuffer(RT_BUFFER_INPUT, RT_FORMAT_FLOAT2, num_vertices);

I spent all day worrying about this problem, and as a result I was thinking that arrays were colliding in memcpy ().

I’m sorry my question seems to be out of optix.

But starting with optixGeometryTriangles, it was necessary to create and apply a program that works in any other file format.

Detlef Roettger, thank you very much. The problem you pointed out was correct. Thank you for your help.