I've posted a similar question to here:
why it crashes when assigning new values to arrays?
But this time, I encountered another problem with arrays again. My code is like this:
double diff[600][800][3];
cv::Mat value ( height, width, CV_8UC3 );
double mean[600][800][3];
....
for ( int i =0; i < 5; ++ i )
{
for ( int j = 0; j < 3; ++j )
{
for ( int m = 0; m < 2; ++m )
{
mean[i][j][m] = 10/m;
diff[i][j][m] = abs ( value.data[value.cols*i+j]-mean[i][j][m]);
}
}
}
It crashed at the line:
diff[i][j][m] = abs ( value.data[value.cols*i+j]-mean[i][j][m]);
I even omitted that line, and just wrote it like:
double test = abs ( value.data[value.cols*i+j]-mean[i][j][m]);
and it compiled, then I added
std::cout << test << std::endl;
it again crashed, and this line also crashed:
diff[i][j][m] = test;
I even changed it like this:
double test = static_cast<double>(abs(value.data[value.cols*i+j]-mean[i][j][m]));
diff[i][j][m] = test;
again, crashed. If I write it like:
diff[i][j][m] = 10;
it compiles. I really cannot figure out the problem. Seems like this is not related to stack overflowing, or datatype. I even tried Aki Suihkonen's answer for my previous question, but it couldn't help. Could someone help me find the problem here??