#include"gdal_priv.h"
#include<armadillo>
#include<vector>
I want to assign a value to the new cube matrix with a known cube matrix. I use the vector container to store the pointer of the known cube matrix. Here is part of my code:
void HRefAly(vector<cube*> ImgData,const char* HRefAlyFilePath,string* RefInf,double Trans[6])
{
int AllRow = ImgData[0]->n_rows;
int AllCol = ImgData[0]->n_cols;
for (int ImgNum = 0; ImgNum < ImgData.size();ImgNum++)
{
int nrow = ImgData[ImgNum]->n_rows;
int ncol = ImgData[ImgNum]->n_cols;
int nslices = ImgData[ImgNum]->n_slices;
cube* point = ImgData[ImgNum];
cube tempImgDataAry(nrow, ncol, nslices);
tempImgDataAry=*point;
......
When running to the last line of code above, vs will report an error:0x00007FFDDD9912DB (vcruntime140d.dll) (demo1.exe)There is an unhandled exception at: 0xC0000005: Read location 0x0000000000000000 an access conflict occurred。
I know that the size of the cube matrix is 100 * 100 * 3 float. I don't think it will exceed the limit. When I use a single pointer to store a single cube matrix instead of a vector container, it will not report an error, but what I want is to process multiple data. And when I add the following code, I can output an address normally:
cout<<ImgData[ImgNum]<<endl;
The position of prompt in case of error is as follows, and prompt in the last line ×:
arrayops::copy(eT* dest, const eT* src, const uword n_elem)
{
if(dest != src)
{
if(is_cx<eT>::no)
{
if(n_elem <= 9)
{
arrayops::copy_small(dest, src, n_elem);
}
else
{
std::memcpy(dest, src, n_elem*sizeof(eT));
}
}
I am a beginner. I hope you can give me your advice. Thank you very much!
I checked sentence by sentence and found that all the previous steps were normal, but I found that in the last step, DeST value was -6.2774385622041925e + 66, SRC value was 0x000000000 {???}, So it's wrong, but I can't see what's wrong.
The armadillo code in case of error is as follows:
template<typename eT>
arma_inline
void
arrayops::copy(eT* dest, const eT* src, const uword n_elem)
{
if(dest != src)
{
if(is_cx<eT>::no)
{
if(n_elem <= 9)
{
arrayops::copy_small(dest, src, n_elem);
}
else
{
std::memcpy(dest, src, n_elem*sizeof(eT));
}
}
else
{
if(n_elem > 0) { std::memcpy(dest, src, n_elem*sizeof(eT)); }
}
}
}
And i found that the following code is ok:
int main() {
cube test(2,2,2);
test.slice(0) << 1 << 2 << endr
<< 3 << 4 << endr;
test.slice(1) << 5 << 6 << endr
<< 7<< 8 << endr;
vector<cube*> teessstt;
cube* point = &test;
teessstt.push_back(point);
cube resut = *teessstt[0];
resut.print();
}
User contributions licensed under CC BY-SA 3.0