OpenImageIO: [BUG] Access violation using IBA::to_OpenCV() with an ImageCache-backed ImageBuf

Describe the bug I get an Exception 0xc0000005 encountered at address ***: Access violation reading location 0x00000000 while trying to convert a HEIC image to OpenCV format. Here is the PoC I’m working with:

#include <algorithm>
#include <filesystem>
#include <format>
#include <iostream>
#include <ranges>
#include <string>
#include <vector>

#include <OpenImageIO/imagebuf.h>
#include <OpenImageIO/imagebufalgo.h>
#include <OpenImageIO/imageio.h>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>

#include "lib.hpp"

namespace fs = std::filesystem;
namespace rng = std::ranges;
namespace vws = std::ranges::views;

auto main() -> int
{
  // Get image paths
  auto images = std::vector<fs::path> {};
  std::transform(fs::directory_iterator("img/"),
                 fs::directory_iterator(),
                 std::back_inserter(images),
                 [](auto const& entry) { return entry.path(); });

  for (auto const& image : images) {
    auto loaded_image = OIIO::ImageBuf(image.string());
    if (not loaded_image.initialized()) {
      std::cout << loaded_image.geterror() << '\n';
      continue;
    }

    auto cv_image = cv::Mat {};
    try {
      OIIO::ImageBufAlgo::to_OpenCV(cv_image, loaded_image, {}, 1);
      cv::imshow(image.filename().string(), cv_image);
    }catch(const std::exception& e){
      std::cout << "Error when converting: " << e.what() << "\n";
      return -1;
    }
  }

  cv::waitKey();
  return 0;
}

To Reproduce

  1. I’m using vcpkg on Windows with openimageio[libheif,opencv] as dependencies
  2. In the folder I have .heic images taken with an iPhone

Expected behavior I would expect to see the images shown via OpenCV highUI.

Evidence When debugging I get a Exception 0xc0000005 encountered at address ***: Access violation reading location 0x00000000 exception.

Platform information:

  • OIIO branch/version: 2.4.9.0
  • OS: Windows 11
  • C++ compiler: Microsoft ® C/C++ Optimizing Compiler Version 19.35.32215 for x64
  • Any non-default build flags when you build OIIO:

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15

Commits related to this issue

Most upvoted comments

Hi! Yes, tested it locally and fully solved the issue for me.