Runtime error in Cuda sample project

I tested the sample cuda project “NvDecodeD3D11” from the Video_Codec_SDK_8.0.14. When I compile it, the error happens at cuvidCtxLockCreate(&g_CtxLock, g_oContext);

It said the access violation executing location 0x0000000000000000 meaning that the g_CtxLock is NULL. How can I solve it?

void
initCudaVideo()
{
    // bind the context lock to the CUDA context
    CUresult result = cuvidCtxLockCreate(&g_CtxLock, g_oContext);
    CUVIDEOFORMATEX oFormatEx;
    memset(&oFormatEx, 0, sizeof(CUVIDEOFORMATEX));
    oFormatEx.format = g_stFormat;

    if (result != CUDA_SUCCESS)
    {
        printf("cuvidCtxLockCreate failed: %d\n", result);
        assert(0);
    }

    CUVIDEOFORMAT videoFormat = g_pVideoSource->format();
    CUVIDDECODECAPS videoDecodeCaps = {};
    videoDecodeCaps.eCodecType = videoFormat.codec;
    videoDecodeCaps.eChromaFormat = videoFormat.chroma_format;
    videoDecodeCaps.nBitDepthMinus8 = videoFormat.bit_depth_luma_minus8;
    if (cuvidGetDecoderCaps(&videoDecodeCaps) != CUDA_SUCCESS)
    {
        printf("cuvidGetDecoderCaps failed: %d\n", result);
        return;
    }
    if (!videoDecodeCaps.bIsSupported) {
        printf("Error: This video format isn't supported on the selected GPU.");
        exit(1);;
    }
    // If XxY is max supported resolution for a codec on a GPU and YxX resolution
    // is also supported then Max Supported width is Max(X, Y) and Max supported height is Max(X, Y)
    // But Max supported MBCount is XxY / 256.
    // E.g. 4096x2304 is max supported resolution and 2304x4096 is also supported then
    // Max Width = 4096, Max Height = 4096, But Max supported MB Count = 4096*2304 / 256 = 36864
    printf("This video format is supported on the selected GPU. \n"
           "    Min resolution supported : %dx%d\n"
           "    Max width supported      : %d\n"
           "    Max height supported     : %d\n"
           "    Max macroblocks supported: %d\n", videoDecodeCaps.nMinWidth, videoDecodeCaps.nMinHeight, 
           videoDecodeCaps.nMaxWidth, videoDecodeCaps.nMaxHeight, videoDecodeCaps.nMaxMBCount);

    std::unique_ptr<VideoDecoder> apVideoDecoder(new VideoDecoder(g_pVideoSource->format(), g_oContext, g_eVideoCreateFlags, g_CtxLock));
    std::unique_ptr<VideoParser> apVideoParser(new VideoParser(apVideoDecoder.get(), g_pFrameQueue, &oFormatEx));
    g_pVideoSource->setParser(*apVideoParser.get());

    g_pVideoParser  = apVideoParser.release();
    g_pVideoDecoder = apVideoDecoder.release();

    // Create a Stream ID for handling Readback
    if (g_bReadback)
    {
        checkCudaErrors(cuStreamCreate(&g_ReadbackSID, 0));
        checkCudaErrors(cuStreamCreate(&g_KernelSID,   0));
        printf("> initCudaVideo()\n");
        printf("  CUDA Streams (%s) <g_ReadbackSID = %p>\n", ((g_ReadbackSID == 0) ? "Disabled" : "Enabled"), g_ReadbackSID);
        printf("  CUDA Streams (%s) <g_KernelSID   = %p>\n", ((g_KernelSID   == 0) ? "Disabled" : "Enabled"), g_KernelSID);
    }
}

@mdigit were you able to solve this problem ? I am having the same problem while using opencv with cuda on windows.