Skip to content

UMat refcount Error when setting UseOpenCL to false #8693

@theaniolad

Description

@theaniolad
System information (version)
  • OpenCV => 3.2
  • Operating System / Platform => Windows 64 Bit
  • Compiler => Visual Studio 2015
Detailed description

I'm currently changing all Mats in my program to UMats and have a crash with some functions (cv::convertTo and cv::reduce) which I don't think should happen.

  1. Code runs fine with Mats
  2. Code runs fine with UMats if UseOpenCL set to true
  3. Code crashes with UMats if UseOpenCL set to false
Steps to reproduce
ocl::setUseOpenCL(false);
auto src = UMat::zeros({ 10,10 }, CV_32FC1);
reduce(src, src, 0, CV_REDUCE_SUM);  //crashes with refcount Error
src.convertTo(src, CV_64FC1); //crashes with refcount Error

The error is:
OpenCV Error: Assertion failed (u->refcount == 0) in cv::StdMatAllocator::deallocate, file opencv\sources\modules\core\src\matrix.cpp, line 214

Now you might say that I should simply use a different output UMat, but I would also like to write functions like this:

void foo(cv::InputArray src, cv::OutputArray dst)
{
   cv::reduce(src, dst, 0, CV_REDUCE_SUM);
   //do other stuff
}
   
int main()
{
   ocl::setUseOpenCL(false);
   auto src = UMat::zeros({ 10,10 }, CV_32FC1);
   foo(src, src);
}

Currently I'm using the following fix to make the program run for all three cases:

 void foo(cv::InputArray src, cv::OutputArray dst)
{
     if (src.isUMat() && !ocl::useOpenCL())
    {
        cv::reduce(src.getUMat(), dst, 0, CV_REDUCE_SUM);
    }
     else 
    {
        cv::reduce(src, dst, 0, CV_REDUCE_SUM);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions