Sign in to follow this  
yewbie

Strange issue with default deconstructors

Recommended Posts

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
[code]> 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()
[/code]

Also the only string in that whole class is the filename and its not anything special.
string Filename; //file name for reloading

Share this post


Link to post
Share on other sites
[quote name='jmastro' timestamp='1318519529' post='4872217']
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.
[/quote]

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote name='way2lazy2care' timestamp='1318595233' post='4872494']
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.
[/quote]

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.

Share this post


Link to post
Share on other sites
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 [url="http://msdn.microsoft.com/en-us/library/ff549557(v=vs.85).aspx"]gflags[/url] 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 [url="https://docs.google.com/viewer?a=v&q=cache:F_lSH9xS7CYJ:daviddahlbacka.com/BugCleaner/DebuggingHeapCorruption.doc+gflags+postmortem&hl=en&gl=uk&pid=bl&srcid=ADGEESgmCSRsQy4n3uyY17X4IBXNCbUlelrDj4PVPMzMgq6vFEPwTZFXdgSoyvPW44oKn7hHlCjPYLYuh83MkhYqi05fke71LG8fIF40EXuOm-oi2qkvQetfe8XFF4qK7wT41ArxFHjR&sig=AHIEtbRyKk8fYrt1HjzCwrxM55uS74sQdg&pli=1"]this document[/url]

4) remember to switch it off again

5) wonder why there isn't a button for this relatively common task in visual studio [img]http://public.gamedev.net/public/style_emoticons/default/cool.gif[/img]

Share this post


Link to post
Share on other sites
[quote name='mrbastard' timestamp='1318610457' post='4872571']
3) use [url="http://msdn.microsoft.com/en-us/library/ff549557%28v=vs.85%29.aspx"]gflags[/url] 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
[/quote]

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:
[b]Note[/b] Incorrect use of this tool can degrade system performance or prevent Windows from starting, requiring you to reinstall Windows.

Share this post


Link to post
Share on other sites
[quote name='yewbie' timestamp='1318611115' post='4872578']
I love you, I never even knew this existed!
[/quote]

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.

[img]http://public.gamedev.net/public/style_emoticons/default/smile.gif[/img]

[quote name='yewbie' timestamp='1318611115' post='4872578']
edit: I love the disclaimer on the bottom of the glflags page:
[b]Note[/b] Incorrect use of this tool can degrade system performance or prevent Windows from starting, requiring you to reinstall Windows.
[/quote]
Wow. You'd think they'd reset the flags on restart [img]http://public.gamedev.net/public/style_emoticons/default/ohmy.gif[/img]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this