In my code I'm encountering a situation where it is running for few hours but crashing at random points after that(SIGSEGV, Segmentation fault). Whenever crash happens, the cv::Mat involved(often different) will have the u parameter as a nullptr. (Link to what u is: https://docs.opencv.org/3.4/d3/d63/classcv_1_1Mat.html#a2742469fe595e1b9036f60d752d08461)
So I'm wondering what this u being a nullptr actually means and if this is the cause for crashing? This is confusing because u is 0x0 or nullptr at other points during execution as well and not just when it crashes.
An example code of how I'm using the mats and causing the u to become 0x0:
#include <opencv2/opencv.hpp>
int main()
{
cv::Mat main_data = cv::Mat::zeros(10, 10, CV_8UC3);
cv::Mat buffer = cv::Mat::zeros(100, 100, CV_8UC3);
cv::Mat valid_data = buffer;
std::cout << "before: " << valid_data.u << std::endl;
memcpy(buffer.data, main_data.data, main_data.rows*main_data.step);
valid_data = cv::Mat(main_data.rows, main_data.cols, main_data.type(), buffer.data, main_data.step[0]);
std::cout << "after: " << valid_data.u << std::endl;
return 0;
}
I have multiple threads and I'm using the above along with locks for sharing data between them.