Updated by Vladislav Vinogradov almost 12 years ago

CvRTrees crashes on destruction if a copy variable of it is made. My guess is that they point to the same region of memory, instead of allocating new memory in a deep copy manner, and crashes when the two objects try to release the same memory. Here is a sample code that will cause the crash:

<pre>
int main()
{
CvRTrees forest;

// Generate some data for training, the values are not important
cv::Mat training(100, 2, CV_32F);
cv::Mat labels(100, 1, CV_32S);

for(int i=0; i < 100; i++) {
training.at<float>(i,0) = rand()/(1.0+RAND_MAX);
training.at<float>(i,1) = rand()/(1.0+RAND_MAX);

if(i % 2 == 0) {
labels.at<int>(i) = 1;
}
else {
labels.at<int>(i) = 0;
}
}

forest.train(training, CV_ROW_SAMPLE, labels);

CvRTrees copy_forest = forest;

return 0;
}
</pre>


Output from GDB

<pre>
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff774dc4f in CvRTrees::clear() ()
</pre>

Back