cjm20
asked on
VC++ app built in VS2012 crashes when run for the first time, then doesn't crash on subsequent runs
I have a VC++ application that I had been compiling in Visual Studio 2012 on a Windows 7 32-bit machine. The application (.exe) would run fine on whatever machine I tried to run it on. However, I've run into a problem recently. I've ported the code over to a Windows 7 64-bit machine, on which I also have Visual Studio 2012 installed. Ever since I changed machines (from 32-bit to 64-bit), I've noticed something strange (and very irritating). After compiling the .exe file, when I launch this .exe for the FIRST TIME on some other machine, the .exe very often will crash on this FIRST RUN (launch), either immediately after launching the application itself, or when opening an input file just after launching the program. However, when I re-launch this .exe, no more crash. I can generally launch this .exe many many times and still no crash. It's as if something on the machine needed to be initialized by the first program launch. So that after that first program launch (and crash), the .exe is then able to run fine because whatever needed to be initialized HAS INDEED BEEN INITIALIZED (this is just a guess, of course).
This is very frustrating.
There is no message box with any meaningful detail accompanying the crash. Instead, there's just a windows dialog saying "Program XYZ has stopped working. A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available."
This is a tough bug to fix. any help would be GREATLY APPRECIATED!!!!!
Thanks very much.
This is very frustrating.
There is no message box with any meaningful detail accompanying the crash. Instead, there's just a windows dialog saying "Program XYZ has stopped working. A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available."
This is a tough bug to fix. any help would be GREATLY APPRECIATED!!!!!
Thanks very much.
What do you get when you try the 1st run under Dependency Walker's (www.dependencywalker.com) 'Profile' mode (be sure to install the 32bit version for that test)?
ASKER
good suggestion. forgot about dependency walker. I'll give it a shot and letcha know how it turns out. Thank you.
Good luck! ;o)
did you check event viewer? is the crash only with release version?
if it happens with debug version as well, you could run the program from visual studio and the debugger should have a user break when crashing.
if it is in release version only you might add trace logs into functions to narrow down the location where the crash happened. the logs should open a log file in append mode, write the log, and close the file after each log. that way you can see after a crash which function was entered but not left.
Sara
if it happens with debug version as well, you could run the program from visual studio and the debugger should have a user break when crashing.
if it is in release version only you might add trace logs into functions to narrow down the location where the crash happened. the logs should open a log file in append mode, write the log, and close the file after each log. that way you can see after a crash which function was entered but not left.
Sara
ASKER
JKR, i gave dependency walker a shot: it's reporting the following errors and warnings:
Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module.
Error: Modules with different CPU types were found.
Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.
Depedency Walker also gives the following error message: "Error opening file. The system cannot find the file specified (2):" on the following list of DLLs:
API-MS-WIN-APPMODEL-RUNTIM E-L1-1-0.D LL
API-MS-WIN-CORE-WINRT-ERRO R-L1-1-0.D LL
API-MS-WIN-CORE-WINRT-L1-1 -0.DLL
API-MS-WIN-CORE-WINRT-ROBU FFER-L1-1- 0.DLL
API-MS-WIN-CORE-WINRT-STRI NG-L1-1-0. DLL
API-MS-WIN-SHCORE-SCALING- L1-1-1.DLL
DCOMP.DLL
IESHIMS.DLL
Having said all this, I'm not sure if the above DLLs and errors are actually the issue. The main reason I say this is that when I run Dependency Walker on the "good" .exe (that being the .exe I built on the Windows 7 32-bit machine), I GET THE EXACT SAME LIST OF ERRORS AND WARNING, VERBATIM. And the "good" .exe does NOT crash.
I've seen some posts online regarding the way Microsoft has changed the code within the App class's member function AddToRecentFileList(....). I am calling this function in my code as follows:
AfxGetApp()->AddToRecentFi leList(psz Path);
where pszPath is defined as follows:
const char* const pszPath;
Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module.
Error: Modules with different CPU types were found.
Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.
Depedency Walker also gives the following error message: "Error opening file. The system cannot find the file specified (2):" on the following list of DLLs:
API-MS-WIN-APPMODEL-RUNTIM
API-MS-WIN-CORE-WINRT-ERRO
API-MS-WIN-CORE-WINRT-L1-1
API-MS-WIN-CORE-WINRT-ROBU
API-MS-WIN-CORE-WINRT-STRI
API-MS-WIN-SHCORE-SCALING-
DCOMP.DLL
IESHIMS.DLL
Having said all this, I'm not sure if the above DLLs and errors are actually the issue. The main reason I say this is that when I run Dependency Walker on the "good" .exe (that being the .exe I built on the Windows 7 32-bit machine), I GET THE EXACT SAME LIST OF ERRORS AND WARNING, VERBATIM. And the "good" .exe does NOT crash.
I've seen some posts online regarding the way Microsoft has changed the code within the App class's member function AddToRecentFileList(....).
AfxGetApp()->AddToRecentFi
where pszPath is defined as follows:
const char* const pszPath;
ASKER
Sara, I haven't tried the event viewer approach but will give it a shot. As for debug versus release mode, the crash is much more repeatable in release mode than debug mode. However, I HAVE been able to get it to crash in debug mode. when I did, the call stack took me to AfxGetApp()->AddToRecentFi leList(psz Path) (which I just referenced above in the post back to JKR). I should have made a better effort at that time (of the crash) to investigate the circumstances, but i didn't, so now I just working from memory....not good :) ....
AfxGetApp()->AddToRecentFiif pszPath is not initialized you should do it.leList(psz Path);
where pszPath is defined as follows:
const char* const pszPath;
why are you using a const pointer pointing to a const char? it is not possible to assign a valid path to the variable beside of casting to non-const.
can you post the whole code around the statement?
Sara
ASKER
To be honest, I've inherited this legacy code. So, the previous programmer (for whatever reason) apparently thought it was a good idea to use const char* const. Here are the code basics surrounding the call to AfxGetApp()->AddToRecentFi leList(psz Path):
OnFileOpen()
{
CString strFileNameAndPath = "";
CFileDialog dlg;
dlg.DoModal();
strFileNameAndPath = dlg.GetPathName();
OpenFile(strFileNameAndPat h);
}
BOOL CMainFrame::OpenFile(const *char const pszPath)
{
ifstreamex strFile(pszPath);
//do some file reading with the strFile object
//close the file reading object
strFile.close();
//add the file name to the list of recently opened files
AfxGetApp()->AddToRecentFi leList(psz Path);
}
OnFileOpen()
{
CString strFileNameAndPath = "";
CFileDialog dlg;
dlg.DoModal();
strFileNameAndPath = dlg.GetPathName();
OpenFile(strFileNameAndPat
}
BOOL CMainFrame::OpenFile(const
{
ifstreamex strFile(pszPath);
//do some file reading with the strFile object
//close the file reading object
strFile.close();
//add the file name to the list of recently opened files
AfxGetApp()->AddToRecentFi
}
ASKER
OK, I was able to fetch some info regarding the crash (when running in RELEASE mode), as follows:
When the crash occurs, I get a windows dialog with the following info:
"An unhandled win32 exception occurred in MyApplication.exe [2844]."
This windows dialog gave me a chance to use VS2012 to debug. So I proceeded....
The VS2012 debugger opened, and I got the following Visual Studio message box:
"Unhandled exception at 0x00B77ABB in MyApplication.exe: 0xC00000005: Access violation reading location 0x00000288."
This looks like a fairly typical array out of bounds issue....
In VS2012's output window, the following LONG list was shown:
'MyApplication.exe' (Win32): Loaded 'C:\Program Files (x86)\MyApplicationFolder\ MyApplicat ion.exe'. Module was built without symbols.
'MyApplicationr.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll .dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kerne l32.dll'. Cannot find or open the PDB file.
'MyApplicationr.exe' (Win32): Loaded 'C:\Windows\SysWOW64\Kerne lBase.dll' . Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\glu32 .dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr t.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\openg l32.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advap i32.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\secho st.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt 4.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspic li.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\crypt base.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32 .dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user3 2.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\lpk.d ll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\usp10 .dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ddraw .dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dcima n32.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\setup api.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cfgmg r32.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleau t32.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32 .dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\devob j.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dwmap i.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmm .dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wsock 32.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ws2_3 2.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\nsi.d ll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winin et.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\api-m s-win-down level-user 32-l1-1-0. dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\api-m s-win-down level-shlw api-l1-1-0 .dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwa pi.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\api-m s-win-down level-vers ion-l1-1-0 .dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\versi on.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\api-m s-win-down level-norm aliz-l1-1- 0.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\norma liz.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\iertu til.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\api-m s-win-down level-adva pi32-l1-1- 0.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\usere nv.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\profa pi.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msimg 32.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winsp ool.drv'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shell 32.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\winsxs\x86_mic rosoft.win dows.commo n-controls _6595b6414 4ccf1df_5. 82.7601.18 201_none_e c80f00e859 3ece5\comc tl32.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\uxthe me.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oledl g.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\winsxs\x86_mic rosoft.win dows.gdipl us_6595b64 144ccf1df_ 1.1.7601.1 8455_none_ 72d576ad86 65e853\Gdi Plus.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleac c.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32 .dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msctf .dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\nvini t.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\PGPma pih.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\PGPhk .dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\winsxs\x86_mic rosoft.win dows.commo n-controls _6595b6414 4ccf1df_6. 0.7601.175 14_none_41 e6975e2bd6 f2b2\comct l32.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\Windo wsCodecs.d ll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntmar ta.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\Wldap 32.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\IPHLP API.DLL'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winns i.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dhcpc svc.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\clbca tq.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wbem\ wbemprox.d ll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wbemc omn.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\crypt sp.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rsaen h.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\RpcRt Remote.dll '. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wbem\ wbemsvc.dl l'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wbem\ fastprox.d ll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdsa pi.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\comdl g32.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\props ys.dll'. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\NV\ig 7icd32.dll '. Cannot find or open the PDB file.
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ig7ic d32.dll'. Cannot find or open the PDB file.
The thread 0x111c has exited with code 0 (0x0).
The thread 0x868 has exited with code 0 (0x0).
The thread 0x1124 has exited with code 0 (0x0).
The thread 0xc8c has exited with code 0 (0x0).
Unhandled exception at 0x00B77ABB in MyApplication.exe: 0xC0000005: Access violation reading location 0x00000288.
And, the Call Stack looks like this:
MyApplication.exe!00b77abb () Unknown
[Frames below may be incorrect and/or missing, no symbols loaded for MyApplication.exe]
MyApplication.exe!00b51970 () Unknown
MyApplication.exe!00c32467 () Unknown
MyApplication.exe!00c336f7 () Unknown
MyApplication.exe!00c2ee55 () Unknown
MyApplication.exe!00c2f5b7 () Unknown
user32.dll!750762fa() Unknown
user32.dll!75076d3a() Unknown
user32.dll!75076ce9() Unknown
user32.dll!75080d27() Unknown
user32.dll!75080d4d() Unknown
opengl32.dll!6ebf60fb() Unknown
user32.dll!750762fa() Unknown
user32.dll!75076d3a() Unknown
user32.dll!75076ce9() Unknown
user32.dll!750777c4() Unknown
MyApplication.exe!00c3bc1e () Unknown
MyApplication.exe!00c3bc8c () Unknown
MyApplication.exe!00c3c293 () Unknown
MyApplication.exe!00c3c450 () Unknown
MyApplication.exe!00d62dcc () Unknown
FMyApplication.exe!00d62ef 4() Unknown
kernel32.dll!7528338a() Unknown
ntdll.dll!77439f72() Unknown
>ntdll.dll!77439f45() Unknown
So, that's all the detail I've got to go on at the moment. I'm currently combing my code looking for any arrays which I might be accessing prior to setting the size, etc.
But please don't hesitate to offer up any advice.....
When the crash occurs, I get a windows dialog with the following info:
"An unhandled win32 exception occurred in MyApplication.exe [2844]."
This windows dialog gave me a chance to use VS2012 to debug. So I proceeded....
The VS2012 debugger opened, and I got the following Visual Studio message box:
"Unhandled exception at 0x00B77ABB in MyApplication.exe: 0xC00000005: Access violation reading location 0x00000288."
This looks like a fairly typical array out of bounds issue....
In VS2012's output window, the following LONG list was shown:
'MyApplication.exe' (Win32): Loaded 'C:\Program Files (x86)\MyApplicationFolder\
'MyApplicationr.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kerne
'MyApplicationr.exe' (Win32): Loaded 'C:\Windows\SysWOW64\Kerne
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\glu32
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\openg
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advap
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\secho
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspic
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\crypt
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user3
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\lpk.d
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\usp10
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ddraw
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dcima
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\setup
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cfgmg
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleau
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\devob
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dwmap
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmm
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wsock
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ws2_3
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\nsi.d
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winin
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\api-m
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\api-m
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwa
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\api-m
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\versi
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\api-m
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\norma
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\iertu
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\api-m
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\usere
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\profa
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msimg
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winsp
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shell
'MyApplication.exe' (Win32): Loaded 'C:\Windows\winsxs\x86_mic
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\uxthe
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oledl
'MyApplication.exe' (Win32): Loaded 'C:\Windows\winsxs\x86_mic
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleac
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msctf
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\nvini
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\PGPma
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\PGPhk
'MyApplication.exe' (Win32): Loaded 'C:\Windows\winsxs\x86_mic
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\Windo
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntmar
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\Wldap
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\IPHLP
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winns
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dhcpc
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\clbca
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wbem\
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wbemc
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\crypt
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rsaen
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\RpcRt
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wbem\
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wbem\
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdsa
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\comdl
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\props
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\NV\ig
'MyApplication.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ig7ic
The thread 0x111c has exited with code 0 (0x0).
The thread 0x868 has exited with code 0 (0x0).
The thread 0x1124 has exited with code 0 (0x0).
The thread 0xc8c has exited with code 0 (0x0).
Unhandled exception at 0x00B77ABB in MyApplication.exe: 0xC0000005: Access violation reading location 0x00000288.
And, the Call Stack looks like this:
MyApplication.exe!00b77abb
[Frames below may be incorrect and/or missing, no symbols loaded for MyApplication.exe]
MyApplication.exe!00b51970
MyApplication.exe!00c32467
MyApplication.exe!00c336f7
MyApplication.exe!00c2ee55
MyApplication.exe!00c2f5b7
user32.dll!750762fa() Unknown
user32.dll!75076d3a() Unknown
user32.dll!75076ce9() Unknown
user32.dll!75080d27() Unknown
user32.dll!75080d4d() Unknown
opengl32.dll!6ebf60fb() Unknown
user32.dll!750762fa() Unknown
user32.dll!75076d3a() Unknown
user32.dll!75076ce9() Unknown
user32.dll!750777c4() Unknown
MyApplication.exe!00c3bc1e
MyApplication.exe!00c3bc8c
MyApplication.exe!00c3c293
MyApplication.exe!00c3c450
MyApplication.exe!00d62dcc
FMyApplication.exe!00d62ef
kernel32.dll!7528338a() Unknown
ntdll.dll!77439f72() Unknown
>ntdll.dll!77439f45() Unknown
So, that's all the detail I've got to go on at the moment. I'm currently combing my code looking for any arrays which I might be accessing prior to setting the size, etc.
But please don't hesitate to offer up any advice.....
>>"Unhandled exception at 0x00B77ABB in MyApplication.exe: 0xC00000005: Access
>>violation reading location 0x00000288."
The read address indeed looks completely off. Can you try tho set the linker set to generate a map file when building your executable? Wiuth that map file, you can locate the faulting code like this: Consider e.g.
(compiled with "cl rvaxcept.cpp /link /map")
which prints
Detected Exception in C:\tmp\cc\rvaxcept.exe at RVA 0x00001088
The map file is
rvaxcept
[time stamp]
Preferred load address is 00400000
Start Length Name Class
0001:00000000 00004938H .text CODE
[...]
Address Publics by Value Rva+Base Lib:Object
0001:00000000 _ExceptionHandler@4 00401000 f rvaxcept.obj
0001:0000007a _FaultingFunction 0040107a f rvaxcept.obj
0001:00000092 _main 00401092 f rvaxcept.obj
0001:000000a7 _printf 004010a7 f LIBC:printf.obj
0001:000000d8 _mainCRTStartup 004010d8 f LIBC:crt0.obj
0001:000001b7 __amsg_exit 004011b7 f LIBC:crt0.obj
[...]
You can see the 'Rva+Base' column, base is given as 'Preferred load address is 00400000'
Add that to the faulting module RVA of 0x00001088 and you get 0x00401088, then look that up in the above (i.e. the 'nearest symbol' and you can see that it is 'FaultingFunction'
0001:0000007a _FaultingFunction 0040107a f rvaxcept.obj
0001:00000092 _main 00401092 f rvaxcept.obj
The address is between main and FaultingFunction, which starts before 0x00401088, the next function is main and starts later.
(BTW, the output of the exception handler is nothing els but the debugger's stack addresses)
>>violation reading location 0x00000288."
The read address indeed looks completely off. Can you try tho set the linker set to generate a map file when building your executable? Wiuth that map file, you can locate the faulting code like this: Consider e.g.
#include <windows.h>
#include <stddef.h>
#include <stdio.h>
LONG
WINAPI
ExceptionHandler(LPEXCEPTION_POINTERS pe) {
char acModule[MAX_PATH];
MEMORY_BASIC_INFORMATION mbi;
HMODULE hMod;
VirtualQuery (pe->ExceptionRecord->ExceptionAddress,&mbi,sizeof(mbi));
ptrdiff_t RVA = (char*)pe->ExceptionRecord->ExceptionAddress - (char*)mbi.AllocationBase;
hMod = (HMODULE) mbi.AllocationBase;
GetModuleFileName(hMod,acModule,sizeof (acModule));
printf( "Detected Exception in %s at RVA 0x%08X\n", acModule, RVA);
return EXCEPTION_EXECUTE_HANDLER;
}
void FaultingFunction () {
LONG* p = NULL;
*p = 42;
}
void main(){
SetUnhandledExceptionFilter (ExceptionHandler);
FaultingFunction ();
}
(compiled with "cl rvaxcept.cpp /link /map")
which prints
Detected Exception in C:\tmp\cc\rvaxcept.exe at RVA 0x00001088
The map file is
rvaxcept
[time stamp]
Preferred load address is 00400000
Start Length Name Class
0001:00000000 00004938H .text CODE
[...]
Address Publics by Value Rva+Base Lib:Object
0001:00000000 _ExceptionHandler@4 00401000 f rvaxcept.obj
0001:0000007a _FaultingFunction 0040107a f rvaxcept.obj
0001:00000092 _main 00401092 f rvaxcept.obj
0001:000000a7 _printf 004010a7 f LIBC:printf.obj
0001:000000d8 _mainCRTStartup 004010d8 f LIBC:crt0.obj
0001:000001b7 __amsg_exit 004011b7 f LIBC:crt0.obj
[...]
You can see the 'Rva+Base' column, base is given as 'Preferred load address is 00400000'
Add that to the faulting module RVA of 0x00001088 and you get 0x00401088, then look that up in the above (i.e. the 'nearest symbol' and you can see that it is 'FaultingFunction'
0001:0000007a _FaultingFunction 0040107a f rvaxcept.obj
0001:00000092 _main 00401092 f rvaxcept.obj
The address is between main and FaultingFunction, which starts before 0x00401088, the next function is main and starts later.
(BTW, the output of the exception handler is nothing els but the debugger's stack addresses)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>>it is either a non-initialized pointer. or it is an offset (relative address) address within a class or struct where the pointer to structure is a null pointer.
Bingo! I was accessing a null pointer to a dialog, in an openGL drawing routine. Because the drawing code gets called a lot (using timers and due to various user actions), this null pointer was being accessed many times over, including when the openGL window is initially drawn at program startup. I've now installed a filter to ensure the pointer is != NULL before accessing the pointer itself. PROBLEM SOLVED. Thanks a million Sara (and Jkr)!!!!
One thing that's strange to me is that this is legacy code. Thus, this null pointer has been accessed for many years, and doesn't seem to have been causing issues (at least not a crash immediately after the application is launched for the first time). This bug has only been "noticeable" since I starting compiling the code on a Windows 7 64-bit machine (VS2012). When I was still compiling on a Windows 7 32-bit machine (VS2012), the bug, while still present in the source code, didn't cause issues (that I noticed, anyway).
Bingo! I was accessing a null pointer to a dialog, in an openGL drawing routine. Because the drawing code gets called a lot (using timers and due to various user actions), this null pointer was being accessed many times over, including when the openGL window is initially drawn at program startup. I've now installed a filter to ensure the pointer is != NULL before accessing the pointer itself. PROBLEM SOLVED. Thanks a million Sara (and Jkr)!!!!
One thing that's strange to me is that this is legacy code. Thus, this null pointer has been accessed for many years, and doesn't seem to have been causing issues (at least not a crash immediately after the application is launched for the first time). This bug has only been "noticeable" since I starting compiling the code on a Windows 7 64-bit machine (VS2012). When I was still compiling on a Windows 7 32-bit machine (VS2012), the bug, while still present in the source code, didn't cause issues (that I noticed, anyway).
It will be helpful for you - and all of us here - to check out in debug mode what is happening in both platforms (32 - 64 bit). There should be the same null pointer accessed in both cases so there should be the same error in both cases. Maybe Sara solved the issue but it looks strange. Are you sure there isn't any - kind of - default settings read from somewhere?
When I was still compiling on a Windows 7 32-bit machine (VS2012), the bug, while still present in the source code, didn't cause issues (that I noticed, anyway).I remember a few debug sessions where I stepped into a member function and the 'this' pointer was NULL. that did not crash as long as the function was read-only and did not dereference a pointer somehow.
in a 64 bit windows, it might be different when the "wrong" address points to protected memory or when the mapping from 32-bit virtual address to 64-bit physical address doesn't accept the pointer value and throws an exception. note, access violation is not a c++ exception but an SEH exception issued by the operation system.
Sara
That's the reason I asked for verification....
It will be good to know if something like that is happening for future knowledge.
It will be good to know if something like that is happening for future knowledge.