views:

271

answers:

3

I have recently caught the following crash in my application:

m_players[0].erase(plr); -- CRASHES HERE

m_players[1].erase(plr);

m_players is declared as:

set<PlayerPointer> m_players[2];

Visual Studio shows that it is "0xC0000005: Access violation writing location 0x0000000000000024."

Compiler: Visual Studio 2008.

Diassembly: 000000014007AA3B mov rcx,qword ptr [this] (crashed on)

So I'm assuming we're dying because of bad "this", since its a first access to this in that function. But since I watched locals/autos, this doesn't seem to be a bad pointer.

Would be nice to get a hint.

+2  A: 

Something is pointing to 0. As you are using Visual Studio compile your application in Debug mode. Type Ctrl+Alt+E and activate the exceptions when they are thrown. This will help you to detect places where things go wrong before an exception handler is run. You can then post the callstack, but I think you will then see&solve the problem easily yourself. I can imagine something bad in the destructor of whatever type is plr.

jdehaan
A: 

I think this has more to do with plr than m_players being already deleted or not available. Can you show how you get plr, is it a local variable or is it being passed as an argument? You might want to create a local variable and then use it in erase function and see if it crashes. This way you can pin point what exactly is causing the crash.

VNarasimhaM
Hmm yes, plr is passed as an argument, will try with a local variable. Thanks
Guest
A: 

any chance the array is global and the problematic code is executed before the array is initialized (can happen if its inside a constructor of a global object etc) ?

rmn
hmm no btw, it crashes on (diassembly) 000000014007AA3B mov rcx,qword ptr [this]
Guest