Ask Your Question
1

SparseMat spawning an breakpoint on .release()

asked 2014-09-04 17:12:35 -0600

pastekh gravatar image

Using OpenCV 2.4.6 (also with 2.4.9) under Win8.1, VS2010 Express, x86 debug or release, I observe the following :

const int dims = 2;
int newSpSize[] = { 80, 81 };
SparseMat test(dims, newSpSize, CV_8U);
test.release(); // Access violation

Code raises a breakpoint (in debug & release) during the call to delete, warning for a potential heap corruption :

inline void SparseMat::release(){
    if( hdr && CV_XADD(&hdr->refcount, -1) == 1 )
        delete hdr; // Access violation
    hdr = 0;
}

The call to Release is not necessary, I just found out this behavior when SparseMat left a function and got deallocated ... this example is simpler and fails too. The same lines used with Mat instead of SparseMat work perfectly. Where is the blunder ? Only other reference here and it doesn't help.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-09-18 07:45:07 -0600

pastekh gravatar image

Solution (for Visual Studio 2010): Following this link, I modified my project Properties/Configuration properties/C++/Code generation/Runtime Library from Multithread(/MT) to DLL Multithread(/MD) in Release, /MTd to /MDd in Debug.

That /MT setup must date back from when I tried to get all the speed I could from DistanceTransform, a year or so ago, which implied TBB compilation (and conflicts ensued with /MD) - without great success. At least this issue is solved - I have now to better understand the implications of this configuration parameter, should it be only for the pretty likely eventuality of my upgrading to 2.4.9 or 3.0 to check over speed improvements (multithread ?) available in DistanceTransform.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-09-04 17:12:35 -0600

Seen: 366 times

Last updated: Sep 18 '14