Access Violations after .NET conversion
Posted on 2007-10-02
I have a visual c++ application that was created in VS 6.0. I have ported this project to VS 8.0 (.net). I have fixed all the compile-time errors associated with this updating process. For example, in .net when declaring a variable in a for loop statement, that variable loses scope when the for loop is finished, as in
for (int i = 0; i < 10; i++) where i would lose scope when the for loop is complete.
So I can now run my program. However, there is a lot of instability. The program crashes frequently, due to Access violations in object arrays. I get crashes accompanied by error messages like the following:
Unhandled exception at 0x006d543d in MyApp.exe: 0xC0000005: Access violation reading location 0xfeeeff26
According to this error message, I'm trying to access an array slot that does NOT exist. However, when I check my array size, the array slot in question DOES EXIST. And when I drag the object into the Watch window, the object DOES EXIST, and has valid data in its member variables. These error messages occur on numerous lines in my code, and with numerous types of objects
My object arrays are of type 'CTypedPtrArray', and the objects that they hold are CObjects that I use in my openGL windows.
An example of a line that might cause a crash would be:
myObjectArray->GetAt(7), where this array has a size of 10; thus, accessing slot 7 should NOT create a crash.
There is not once specific line or lines in the code where this crash occurs. And sometimes a line may cause a crash, and other times it creates no crash.