I build a multithreaded system with OpenCV, which creates some images, assigns them into a vector and sends each image into a different thread.
This is how it looks like:
std::vector<cv::Mat> images;
for (int i = 0 ; i < 10 ; i++) {
images.push_back(cv::Mat(/* bla bla */));
cv::Mat& mat = images.back();
std::thread(some_function_name, &mat)
}
// Wait here for all threads to join (didn't show its code)
It seems that when the thread gets the pointer to the Mat object, the Mat object doesn't anymore exist. Is it possible that although it was immediately assigned to the vector, it was actually destroyed when the loop ended, as it was wiped off the stack?