Strange issue with default deconstructors

Started by
8 comments, last by iMalc 12 years, 6 months ago
I have a textureloader I made awhile back to dynamically load textures etc etc, well it has always worked fine up until about a week ago.
Now I never changed anything with my textureloader but now on exit of my game as it runs through all the default deconstructors it will sometimes crash when de-allocating a string!

I included the callstack here, I know some of these error messages can be very cryptic, but it just looks like its trying to release a string?
Any help, or any idea about how to go about debugging this would be greatly appreciated!

Unhandled exception at 0x63eaad4a (msvcp100d.dll) in AlphaProjectV2.exe: 0xC0000005: Access violation reading location 0x00000005.
> msvcp100d.dll!std::_Container_base12::_Orphan_all() Line 201 + 0x12 bytes C++

Here is the callstack
> msvcp100d.dll!std::_Container_base12::_Orphan_all() Line 201 + 0x12 bytes C++
AlphaProjectV2.exe!std::_String_val<char,std::allocator<char> >::~_String_val<char,std::allocator<char> >() Line 478 + 0xb bytes C++
AlphaProjectV2.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::~basic_string<char,std::char_traits<char>,std::allocator<char> >() Line 755 + 0xf bytes C++
AlphaProjectV2.exe!TEXTUREMANAGER::~TEXTUREMANAGER() + 0x66 bytes C++
AlphaProjectV2.exe!GamePlayGraphics::~GamePlayGraphics() + 0xc6 bytes C++
AlphaProjectV2.exe!GraphicsEngine::~GraphicsEngine() + 0x69 bytes C++
AlphaProjectV2.exe!Game::~Game() + 0x78 bytes C++
AlphaProjectV2.exe!`dynamic atexit destructor for 'MyGame''() + 0x28 bytes C++
msvcr100d.dll!doexit(int code, int quick, int retcaller) Line 567 C
msvcr100d.dll!exit(int code) Line 393 + 0xd bytes C
AlphaProjectV2.exe!__tmainCRTStartup() Line 568 C
AlphaProjectV2.exe!WinMainCRTStartup() Line 371 C
kernel32.dll!767a339a()
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
ntdll.dll!77b09ed2()
ntdll.dll!77b09ea5()


Also the only string in that whole class is the filename and its not anything special.
string Filename; //file name for reloading
Advertisement
The problem may actually lie elsewhere...maybe you're corrupting memory in other code. I'd check any changes made around the time that this started happening.

The problem may actually lie elsewhere...maybe you're corrupting memory in other code. I'd check any changes made around the time that this started happening.


Thanks for the reply, I will check.
Mostly it was pathfinding stuff that I added, good to know that it could be somewhere else though... That dramatically expands my search =p
I have couple ideas..

Do you use raw pointers to store any of those classes as data members? If so, double check all resource handling, at least Copy constructors, destructors and assignment operators. Implicitly generated do not work. Try to set the pointers to zero if you are manually deleting anything, just to rule out any double deletion issues.

Verify that you're not messing with what c_str() returns to you.
Have you rewritten anything to do with your allocator? I know often the problems are more sporadic and less tested when the allocator deallocates, and depending on how your program exits you may never run into problems.

Have you rewritten anything to do with your allocator? I know often the problems are more sporadic and less tested when the allocator deallocates, and depending on how your program exits you may never run into problems.


I've gone over my texture loader class over and over and I really don't see anything that would cause that (its not a very big class)
I am just going to comment large portions of code to narrow it down, I just wish the debug output would give me more hints =p

Edit: and to answer your question, many of my allocators have changed since this problem cropped up but textureloader has not changed.
If you've spent more than a few hours on this, here's what I would do:

1) assume a bug elsewhere in your code is overwriting the pointer stored by the string, or other similar source of heap corruption

2) assume that if you were going to find the bug by examination, you would have already done so - you are looking at your diffs, right?

3) use gflags to temporarily enable 'full heap' option for your process so that you're more likely to get an actual access violation when your heap corruption occurs

Actually, read this document

4) remember to switch it off again

5) wonder why there isn't a button for this relatively common task in visual studio cool.gif
[size="1"]

3) use gflags to temporarily enable 'full heap' option for your process so that you're more likely to get an actual access violation when your heap corruption occurs


I love you, I never even knew this existed!
I found it, I was writing to a array:
int MapPath[200][200]
using a formula to get my cordinates, well due to a quirk in how I wrote my formula I would sometimes get a result outside of my range of 200.
I have fixed the offending formula, I have added range checking, not sure why I didn't to being with!

edit: I love the disclaimer on the bottom of the glflags page:
Note Incorrect use of this tool can degrade system performance or prevent Windows from starting, requiring you to reinstall Windows.

I love you, I never even knew this existed!


HTH. Yeah, it's one of those tricks that deserves to be much more well known, given the incredible amount of time it can save.

smile.gif


edit: I love the disclaimer on the bottom of the glflags page:
Note Incorrect use of this tool can degrade system performance or prevent Windows from starting, requiring you to reinstall Windows.

Wow. You'd think they'd reset the flags on restart ohmy.gif

[size="1"]
Please note that they are not called "deconstructors", they are called "destructors".

To deconstruct is to take apart, to destruct is to destroy.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

This topic is closed to new replies.

Advertisement