C++ :: access violation error :: no source code :: show disassembly

Started by
14 comments, last by ApochPiQ 12 years, 9 months ago
Hi

I'm writing a library in C++ for OpenGL and in the same time a program to test this library. Recently I made some changes which produced an error.

Unhandled exception at 0x7c91ac4a in testOpenGL.exe : 0xC0000005:
Access violation writing location 0x00000010.

Pressing Break appears this message:

There is no source code available for the current location.

I can press Ok and Show Disassembly. I press Show Disassembly and the assembly code of my program (I guess) shows up. Here it is:

7C91ABEA nop
7C91ABEB nop
7C91ABEC nop
7C91ABED nop
7C91ABEE nop
7C91ABEF mov edi,edi
7C91ABF1 push ebp
7C91ABF2 mov ebp,esp
7C91ABF4 sub esp,68h
7C91ABF7 push ebx
7C91ABF8 push esi
7C91ABF9 mov esi,dword ptr [ebp+8]
7C91ABFC xor ebx,ebx
7C91ABFE cmp esi,7C97E178h
7C91AC04 mov dword ptr [ebp-8],ebx
7C91AC07 sete byte ptr [ebp+0Bh]
7C91AC0B mov eax,dword ptr fs:[00000018h]
7C91AC11 movzx ecx,byte ptr [ebp+0Bh]
7C91AC15 mov dword ptr [eax+0F84h],ecx
7C91AC1B cmp byte ptr ds:[7C97E0C4h],bl
7C91AC21 jne 7C91A4DB
7C91AC27 mov al,byte ptr ds:[7C97E1E8h]
7C91AC2C neg al
7C91AC2E push edi
7C91AC2F sbb eax,eax
7C91AC31 not eax
7C91AC33 and eax,7C97E1E0h
7C91AC38 mov edi,eax
7C91AC3A mov eax,dword ptr [esi+10h]
7C91AC3D cmp eax,ebx
7C91AC3F mov dword ptr [ebp-4],eax
7C91AC42 je 7C91ACE6
7C91AC48 mov eax,dword ptr [esi]
7C91AC4A inc dword ptr [eax+10h] <<----------------------------------------------------------------<<
7C91AC4D mov eax,dword ptr [ebp-4]
7C91AC50 and eax,1
7C91AC53 mov dword ptr [ebp-18h],eax
7C91AC56 mov eax,dword ptr [esi]
7C91AC58 inc dword ptr [eax+14h]
7C91AC5B test byte ptr ds:[7FFE02F0h],1
7C91AC62 jne 7C9439C6
7C91AC68 cmp dword ptr [ebp-18h],ebx
7C91AC6B push edi
7C91AC6C push ebx
7C91AC6D jne 7C92BE6D
7C91AC73 push dword ptr [ebp-4]
7C91AC76 call 7C90DF4E
7C91AC7B cmp eax,102h
7C91AC80 je 7C943A51
7C91AC86 cmp eax,ebx
7C91AC88 jl 7C943B0E
7C91AC8E cmp byte ptr [ebp+0Bh],bl
7C91AC91 pop edi
7C91AC92 je 7C91ACAC
7C91AC94 mov eax,dword ptr fs:[00000018h]
7C91AC9A mov eax,dword ptr [eax+24h]
7C91AC9D mov dword ptr [esi+0Ch],eax
7C91ACA0 mov eax,dword ptr fs:[00000018h]
7C91ACA6 mov dword ptr [eax+0F84h],ebx
7C91ACAC pop esi
7C91ACAD pop ebx
7C91ACAE leave
7C91ACAF ret 4
7C91ACB2 nop
7C91ACB3 nop
7C91ACB4 nop
7C91ACB5 nop
7C91ACB6 nop


And here is the part of the source code of my library that has the problem:


bool myAnotherClass::myMethod(string name) {
if(pointerTo_myStruct == NULL){
pointerTo_myStruct = new myStruct(); // <<--------------------<< Source code of the myStruct (1)
pointerTo_myStruct->Name = name;
pointerTo_myStruct->pointerTo_myClass = new myClass(this);
}else{

//Does not enter here for the moment

}
};

return true; // <<-----------------------------<< Here is were the error pops up.
}

/*(1)*/ struct myStruct{

myStruct(){ Name = "No Name"; pointerTo_myClass = NULL; Next = NULL; }
//~myStruct(){ delete Next; };

string Name;
myClass* pointerTo_myClass;
myStruct* Next;
};


I'm not pasting the source code of myClass because it's not new and it has no changes. All tested and working and irrelevant.
Now the changes I've made was: adding this struct and start using the string template class (#include string.h) which, I think, there is the problem. Something
that I'm not using right.

if anyone can think anything I'll appreciate it.
Ask anything you want.

Thanks
Advertisement
If you are using a pointer to store and call MyClass, my first suggestion would be to check if the pointer is valid before the call to myMethod() is made. It is possible for the function to execute, even though the pointer is invalid.


myClass* pointer = new myClass();

...

pointer->myMethod(); // Check if pointer is valid here.

"I can't believe I'm defending logic to a turing machine." - Kent Woolworth [Other Space]

There are no errors in the code you posted, the error is somewhere else in the code that is "irrelevant. "
Wisdom is knowing when to shut up, so try it.
--Game Development http://nolimitsdesigns.com: Reliable UDP library, Threading library, Math Library, UI Library. Take a look, its all free.
Make sure you have debug symbols available (see Google for instructions on setting up a connection to the Microsoft Symbol Server) and then post the call stack from the crash.

Sounds like you're either dying in external code (in which case symbols will help you ascertain where exactly that's happening) or your local compiler environment got borked and you're missing the actual debug information for your program. In the latter case, make sure you can set a breakpoint in a known valid point in the code and see that trip in the debugger; if not, we'll have to figure out how to unscrew the debug metadata for you.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Sorry, I've made a change in the code.

Yes Rattrap, the pointer is valid and the myAnotherClass is properly initialized. It have tested it before i make the changes. It's working.

smasherprog and for all the ignorants out there, please if you don't understand something, don't post.
Read the message. It's says "There is no source code" which means the source that exists it's syntacticly correct. It's compiling and running. The error happens in the run-time.
Something in the return of the myMethod produces the error.

ApochPiQ, I have made the that trip in the debugger use said and the error pops up in the return of myMethod.
Here's what I would do:

1. Ensure the call stack is kosher
2. Double check for any buffer overruns or any stack corruption in any of the code or calling code.
3. Trace through the code, double check status of local variables.
4. You mentioned this was a library, so double check that compiler settings match. If not, then open the library code directly and build a minimal sample on top of it.

smasherprog and for all the ignorants out there, please if you don't understand something, don't post.
Read the message. It's says "There is no source code" which means the source that exists it's syntacticly correct. It's compiling and running. The error happens in the run-time.
Something in the return of the myMethod produces the error.

There is a very important difference between symptom and cause. What you're seeing is the symptom, and the error is indeed triggered within the runtime. The cause, on the other hand, which is the actual source of the error and what you have to fix, is likely in your own code. The runtime should be the last place where you look for the cause. What you deemed irrelevant may very well contain the cause.
I did not mean to insult you, only to emphasis a belief that everyone --including me-- has had at one time when growing as a programmer. Sometimes we think that we have coded something perfect, and the code does indeed run perfectly. Then, when new code is added, things break. We often blame the new code added, which usually is correct. However, if the new code added is really simple and easy to figure out -- like the code you are displaying--, then the odds are that the broken problem is in other areas of your code. I have spent many days searching for a problem in the wrong area because I was sure that my code was perfect --it wasn't.


So, I will repost my original statement: unfortunately, the error is likely in another area of your code.
Wisdom is knowing when to shut up, so try it.
--Game Development http://nolimitsdesigns.com: Reliable UDP library, Threading library, Math Library, UI Library. Take a look, its all free.
[color=#1C2837][size=2]
[color=#1C2837][size=2]
Access violation writing location 0x00000010.
[color=#1C2837][size=2][/quote]
[color=#1C2837][size=2]

[color=#1C2837][size=2] Just a guess, but maybe you could try printing the 'this' pointer in myMethod. Seeing the above says it can't write to 0x000000010, its possible the this pointer is null.
The reason for insisting that the error is in myMethod is because the error is happening right at the return point. I don't know much of assembly but I know that in the call/return state of a function, a trade-off between memories (I don't know which memories) is taking place. I could check for a millionth time the rest code and post any suspicious part but I will insist in the myMethod theory.

This topic is closed to new replies.

Advertisement