I’ve made a minimal repro to show an access violation when calling nvEncOpenEncodeSessionEx. I’m sure I’ve just made a really dumb mistake here and forgotten to initialise something. All the asserts are fine and I get to the last statement no problem. Can anyone spot what it is?
“Exception thrown at 0x00007FF902328B37 (nvcuda64.dll) in vts.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.”
Build: I’m on Windows 11 and have a 4080, with VS 2022 and a 64 bit debug build. My driver version is 536.67. I’ve installed CUDA 12 and the SDK (12.1.14).
Here’s the repro:
#include <cassert>
#include <array>
#include <cuda.h>
#include <nvEncodeAPI.h>
int main()
{
auto cuda_count_gpu = 0;
auto cuda_device = CUdevice();
auto cuda_context = CUcontext();
auto cuda_encode_functions = NV_ENCODE_API_FUNCTION_LIST() = { NV_ENCODE_API_FUNCTION_LIST_VER };
auto cuda_encode_session_handle = static_cast<void *>(nullptr);
// Init CUDA.
assert(cuInit(0) == CUDA_SUCCESS);
assert(cuDeviceGetCount(&cuda_count_gpu) == CUDA_SUCCESS);
assert(cuda_count_gpu > 0);
assert(cuDeviceGet(&cuda_device, 0) == CUDA_SUCCESS);
assert(cuCtxCreate(&cuda_context, 0, cuda_device) == CUDA_SUCCESS);
// Init API.
assert(NvEncodeAPICreateInstance(&cuda_encode_functions) == NV_ENC_SUCCESS);
// Init session.
auto session_parameters = NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS() =
{
.version = NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS_VER,
.deviceType = NV_ENC_DEVICE_TYPE_CUDA,
.device = &cuda_context,
.reserved = 0,
.apiVersion = NVENCAPI_VERSION,
.reserved1 = 0,
.reserved2 = NULL
};
assert(cuda_encode_functions.nvEncOpenEncodeSessionEx(&session_parameters, &cuda_encode_session_handle) == NV_ENC_SUCCESS);
}