1
votes
unsigned char* createImageBuffer(unsigned int bytes)
{
    unsigned char* ptr;
    cudaSetDeviceFlags(cudaDeviceMapHost);
    cudaHostAlloc(&ptr, bytes, cudaHostAllocMapped);    
    return ptr;
}


    cv::Mat sGray(frame.size(), CV_8U, createImageBuffer(frame.size().width * frame.size().height));

    cv::Mat dGray(frame.size(), CV_8U, createImageBuffer(frame.size().width * frame.size().height));

    cv::Mat eGray(frame.size(), CV_8U, createImageBuffer(frame.size().width * frame.size().height));

The problem during debugging is regarding accessing restricted memory at 0x00000000. The function is supposed to return a pointer to the place of image bytes allocation however it gives me the bad ptr value.

Output:

First-chance exception at 0x0c10e473 in improc.exe: 0xC0000005: Access violation reading location 0x00000000. Unhandled exception at 0x0c10e473 in improc.exe: 0xC0000005: Access violation reading location 0x00000000.

The video to the tutorial I followed: https://youtu.be/j9vb5UjQCQg

1
Are you sure that frame is not empty?ilke444
Access violation reading location 0x00000000 means createImageBuffer returned null pointer. And the most possible cause is what @ilke444 indicated - frame.size() returning 0.pSoLT

1 Answers

1
votes

The API is probably unable to allocate enough memory. Check return value of cudaHostAlloc (cf. doku on cudaHostAlloc):

unsigned char* createImageBuffer(unsigned int bytes)
{
    unsigned char* ptr;
    cudaSetDeviceFlags(cudaDeviceMapHost);
    cudaError_t allocResult = cudaHostAlloc(&ptr, bytes, cudaHostAllocMapped);
    if (allocResult != cudaSuccess) {
      // could be cudaErrorMemoryAllocation; The API call failed because
      // it was unable to allocate enough memory to perform
      // the requested operation.
      return nullptr;
    }
    return ptr;
}