Friday, August 17, 2012

How to Fix Visual C Assertion Failure


1. Launch Visual Studio. Select your application's project. Click on the right-most drop-down menu in the project workspace. It shows two entries: 'Win32 Debug' and 'Win32 Release.' Choose 'Win32 Debug.'
2. Click on 'Build' in the project workspace menu or select 'Build <application project name>' to rebuild the application in Debug mode.
3. Run the new build within Visual Studio.
4. Note the information provided such as source filename, line number, module name or library when you get the 'Assertion Failure' message. Press 'Retry' to debug the source code.
5. Press 'Alt+7' ('Alt' and then '7' while Alt is pressed) to bring up the Debug window. Look in the call stack from top to bottom, and go to the first function from your application source code, skipping the system calls that are a part of the code generated by the compiler.
6. Read your application function line by line. Note and track each function parameter, local, global and static variable used. Look for pointer variables being used without a conditional statement that checks if the pointer is NULL. Look for uninitialized pointers and array indices gone out of bounds.
7. Correct programming errors that you find in and/or around this piece of code, possibly in the parent function or previously called function.
8. Follow the debug call stack to see which line in the application caused the violation if the error is not yet diagnosed. Step through the nested calls to detect the error. These could be a combination of MFC, Windows library and system calls.
9. Use the utility 'PageHeap.exe' to debug complex Windows Memory Heap reference errors that cannot be caught by diagnosing application code. Use the information given by the assertion message for further tracking.