PDA

View Full Version : Qt application crashing - Heap errors?



System123
23rd August 2010, 12:21
Hi

I am busy with my 2nd year computer science project, but I have run into some issues. The problems start when I use QFileDialog, as shown below:



QString fileName = QFileDialog::getOpenFileName(parentWidget(), tr("Open File"),
".",tr("DEM Files (*.map *.dem *.bmp);;All Files(*)"),0,QFileDialog::DontUseNativeDialog);


I get the following message in my Application output window

Lowest section in C:\PROGRA~1\COMMON~1\MICROS~1\OFFICE14\Cultures\OF FICE.ODF is .text at 10001000
Lowest section in C:\PROGRA~1\MICROS~3\Office14\1033\GrooveIntlResou rce.dll is .text at 10001000

I am not to sure if I should worry about this or why it is happening.

the next error I get is:
HEAP[Terrain_Generator.exe]:
Invalid address specified to RtlFreeHeap( 003E0000, 0C1121C8 )

which causes my program to crash. It Happens when I return the stat variable, see code below.

My analysis method that causes the crash


TerrainStats* TerrainAnalyser::analyseTerrain(const HeightMap &map, int sweeps, int radius){
Levels = sweeps;

if (sweeps < 0)
sweeps = -sweeps;

GaussKernel Akern = makeBlurKernel(radius);
HeightMap tmp(map);
HeightMap tmp2(map);
TerrainStats* stats = new TerrainStats(sweeps);

for (int cnt = 0; cnt < sweeps; cnt++){
tmp = GaussianBlur(tmp,Akern);
tmp2 = (tmp2 - tmp);
populateStats(tmp2,stats->levelStats[cnt],cnt);
tmp2 = tmp;
}

return stats; //<- This is what causes the problem
}


I tried a simpler example but it doesn't crash, so it must be something stupid that I am overlooking. I have spent 2 days trying to find it but with no success.

I call the method as follows



TerrainStats *stats = TAnalyser->analyseTerrain((*current),6,32);
populateTable((*stats));


Thanks in advance

yakin
23rd August 2010, 15:05
the posted code looks ok. When you leave the method with
return stats; the local variables will be cleaned up. Is it possible that the crash was caused in destruction of the objects from type HeightMap or GaussKernel. Do you have a stacktrace or a debugger output?

System123
23rd August 2010, 16:44
Thanks

You are correct, it is my delete[] statements that are causing the errors, but I don't know why because I am quite sure I implemented them correctly. All my Heighmap and GaussKernel structs can only be created using the constructor.

I have reprogrammed the way somethings work, but I am still getting the same problems.

here is the stack trace from Qt Creator



0 ntdll!RtlQueryEnvironmentVariable_U C:\Windows\system32\ntdll.dll 0
1 ntdll!RtlAreBitsClear C:\Windows\system32\ntdll.dll 0
2 ntdll!RtlAreBitsClear C:\Windows\system32\ntdll.dll 0
3 ntdll!RtlUnicodeStringToOemString C:\Windows\system32\ntdll.dll 0
4 ntdll!RtlpSetUserPreferredUILanguages C:\Windows\system32\ntdll.dll 0
5 ntdll!RtlTraceDatabaseValidate C:\Windows\system32\ntdll.dll 0
6 ntdll!RtlUnicodeStringToOemString C:\Windows\system32\ntdll.dll 0
7 msvcrt!malloc C:\Windows\system32\msvcrt.dll 0
8 operator new 0
9 operator new[] 0
10 HeightMap::HeightMap Types.cpp 29
11 TerrainAnalyser::analyseTerrain terrainanalyser.cpp 97
12 GUI::openFile GUI.cpp 160
13 GUI::qt_metacall moc_GUI.cpp 71
14 QMetaObject::activate qobject.cpp 3104
15 QMetaObject::activate qobject.cpp 3198
16 QAction::triggered moc_qaction.cpp 236
17 QAction::activate qaction.cpp 1160
18 QMenuPrivate::activateCausedStack qmenu.cpp 967
19 QMenuPrivate::activateAction qmenu.cpp 1060
20 QMenu::mouseReleaseEvent qmenu.cpp 2254
... <More>


Attatched is the debugger output. 5094
If anyone would like to look at the code e-mail me and I will send the full code to you, I don't want to attach it because it is a current project.

Thanks

System123
23rd August 2010, 21:14
Thanks for the help, it was a stupid problem of me not editing using the correct variable when in the array, so the array index was negative.