Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

SparseMat spawning an breakpoint on .release()

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.