PDA

View Full Version : error: exited with code -1073740940 ask for help



longkimari
26th February 2020, 02:15
Hi guys:

I was stucked in a problem, the program can be built and run for a about 19 minutes, and then exited with code -1073740940.
I don't know where can find the code means ?
Develop environment : Qt 5.14.0 / Windows 10

After checked my code and did a lot of test , I found that when I disable some code sections, it would run for a long time.
The function was reading a block of dem data from memory, and it runs a about 60 times per second.


short int* DemPreLoad::LoadDemData_Area()
{
short int* crop = (short int*)malloc(sizeof(short int) * _Terrian_Range * _Terrian_Range*4); // _Terrian_Range is const for 100
Location location = getLocation(); // According to longtitude & latitude caculate which row & col the right data in the dem data map
Location beginlocation;
int beginIndex;

beginlocation.col = location.col - _Terrian_Range;
beginlocation.row = location.row - _Terrian_Range;
beginIndex = (int)(beginlocation.col + beginlocation.row * 43200);

for (int rows = 0; rows < _Terrian_Range * 2; rows++)
{
for (int cols = 0; cols < _Terrian_Range * 2; cols++)
{
crop[cols + rows * _Terrian_Range*2] = _DataNow[beginIndex + cols];
if (demlow>_DataNow[beginIndex + cols]) demlow=_DataNow[beginIndex + cols];
if (demhigh<_DataNow[beginIndex + cols]) demhigh=_DataNow[beginIndex + cols];
}
beginIndex += 43200;
}

return crop;
}
My questions are :
1? Where could I find the code means.
2? How could fix the problem(s).

Thanks a lot.

Lesiok
26th February 2020, 09:10
1. In line 3 You are allocating memory. You don't test if this was succesfull.
2. Wherever you free that memory ?

d_stranz
26th February 2020, 17:37
If you modify your API a little bit, you could avoid this memory leak:



void DemPreLoad::LoadDemData_Area( std::vector< short int > & crop )
{
crop.resize( _Terrian_Range * _Terrian_Range * 4, 0 );
// ...
}


or



std::vector< short int > DemPreLoad::LoadDemData_Area( )
{
std::vector< short int > crop( _Terrian_Range * _Terrian_Range * 4, 0 );
// ...
return crop;
}


And of course you would have to modify your calling code to use a vector instead of a pointer to an array, but since vector overloads operator[] you can access the members of the vector using crop[ i ] in exactly the same way as if you had "crop" defined as an int * pointer and used crop[ i ]. If you actually need to access the vector as a pointer to an array, then &(crop[0]) returns that pointer.

longkimari
28th February 2020, 08:35
I've rewrote the code like:


std::vector<short int> DemPreLoad::LoadDemData_Area()
{
std::vector<short int> crop( _Terrian_Range * _Terrian_Range * 4, 0 );
Location location = getLocation();
Location beginlocation;
int beginIndex;
beginlocation.col = location.col - _Terrian_Range;
beginlocation.row = location.row - _Terrian_Range;
beginIndex = (int)(beginlocation.col + beginlocation.row * 43200);

for (int rows = 0; rows < _Terrian_Range * 2; rows++)
{
for (int cols = 0; cols < _Terrian_Range * 2; cols++)
{
crop[cols + rows * _Terrian_Range*2] = _DataNow[beginIndex + cols];
if (demlow>_DataNow[beginIndex + cols]) demlow=_DataNow[beginIndex + cols];
if (demhigh<_DataNow[beginIndex + cols]) demhigh=_DataNow[beginIndex + cols];
}
beginIndex += 43200;
}
//QDebug("%d\n",crop[0]);
// putTestDataToFile(&(crop[0]));
return crop;
}

But it still get the error: exited with code -1073740940 after running about 30 minutes.

Lesiok
28th February 2020, 11:18
-1073740940 it is 0xC0000374 in HEX. Ask Google what this is.

d_stranz
1st March 2020, 18:46
int beginIndex;
beginlocation.col = location.col - _Terrian_Range;
beginlocation.row = location.row - _Terrian_Range;
beginIndex = (int)(beginlocation.col + beginlocation.row * 43200);

// ...

beginIndex += 43200;


And when you have figured out what Google is telling you, maybe this code might have something to do with it. For one "magic numbers" (like 43200) are always suspect. Is this number some type of a constant for -all- DEM files? For another, when you are computing "beginLocation" you are -subtracting- "_Terrain_Range", which also seems suspicious.

There might be good (and valid) reasons for this, but any time I see code like this I think, "there's an access error that's going end up corrupting memory".

If you are accessing data using C-style pointers and pointer arithmetic, then the code doesn't care if the pointer is inside an array or data structure or not. It doesn't do any bounds checking. So if you aren't computing the pointer locations correctly, your code could be reading from (or worse) writing to any old random place in memory.