Optix PathTracer: why am I getting exception if I try to render an empty scene?

I am building a custom test renderer using the Optix 7.6 path tracer sample . My OPENNurbs-based triangle mesh geometry is loaded into the corresponding vectors (g_vertices, d_mat_indices, etc) and I can successfully see the rendered triangles as expected.
Testing what happens if I try to render an empty scene I am getting an exception at:

	const size_t mat_indices_size_in_bytes =TRIANGLE_COUNT * sizeof(uint32_t);
	CUDA_CHECK(cudaMalloc(reinterpret_cast<void**>(&d_mat_indices), mat_indices_size_in_bytes));
	CUDA_CHECK(cudaMemcpy(
		reinterpret_cast<void*>(d_mat_indices),
		g_mat_indices.data(),
		mat_indices_size_in_bytes,
		cudaMemcpyHostToDevice
	));

What check should I do in order to avoid this exception?

If your scene is empty and there is no data inside the g_vertices and g_mat_indices then these allocations would be zero bytes which isn’t supported in CUDA.
Building the OptiX acceleration structures also wouldn’t work with no input data.

If you still wanted to render an empty scene, all what would be invoked when shooting rays should be the miss program and that is easy.

First you would obviously need to protect all your application code against such empty input data conditions and not call any of the functions which don’t work in that case.

That would result in a null traversable handle inside the launch parameters because there has not been any AS built.
A null traversable handle is a valid input to optixTrace and will immediately call the miss program, so you should see an empty scene with just background from the miss program.

I would try that with a scene which works first and then just override the launch parameter traversable handle with null to see if it renders an empty scene.