Torch::from_blob gives access violation in debug mode but is fine in release mode!

The following snippet of code which converts an image into a tensor, results in access violation exception when run in debug mode only.

auto ToTensor(cv::Mat img, bool show_output = false, bool unsqueeze = false, int unsqueeze_dim = 0)
{
    try
    {
        if (show_output)
            std::cout << "image shape: " << img.size() << " channels: " << img.channels() << " depth: " << img.depth() << " type: " << img.type() << std::endl;
        at::Tensor tensor_image = torch::from_blob(img.data, { img.rows, img.cols, img.channels() }, at::kByte);

        if (unsqueeze)
        {
            tensor_image.unsqueeze_(unsqueeze_dim);
            std::cout << "tensors new shape: " << tensor_image.sizes() << std::endl;
        }

        if (show_output)
        {
            std::cout << tensor_image.slice(2, 0, 1) << std::endl;
        }
        
        if (show_output)
            std::cout << "tenor shape: " << tensor_image.sizes() << std::endl;
        
        return tensor_image;
    }
    catch (const c10::Error& e)
    {
        std::cout << "error occured: " << e.msg() << e.what() << std::endl;
        return torch::tensor({ 0.229, 0.224, 0.225 });
    }
}
And here is  the full exception message :  

exception message :

Exception thrown at 0x00007FF70568DB3A in test.exe: 0xC0000005: Access violation writing location 0x0000000000000003.

Whats wrong here?

OK, it was caused becasue of the release libs were in the PATH and it would read the libs and crash.
It’d be great to have different names for debug and release codes so the headaches regarding these would be minimized.