Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / C++ Guru Help Wanted: Mysterious Crashing when Terminating Game...

Author
Message
TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 30th Jun 2009 15:43 Edited at: 8th Jul 2009 00:17
Taking a stab at learning C++ OOP features rewritting my second 3D arcade games, cellular. The following code compiles without any errors and runs fine. However, when I exit the app, it crashes. I've pulled out what little hair remains on top of my head trying to figure it out. It crashes the debugger too. I'm stumped Please help C++ Gurus.

jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 30th Jun 2009 18:53
what is the error?
without delete db3DResourceSupply;
it will cause leaks.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Jun 2009 22:23
My guess would be the double delete of the Defender::Instance array, once in Destroy and a second time in Stop

TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 1st Jul 2009 12:15
Quote: "what is the error?"
I'm not exactly sure what the error is. On exit, it crashes promping me to send the log to Microsoft. The complete source is posted above in the code segment. I wonder if anyone one else can run it without a hitch?

Quote: "guess would be the double delete of the Defender::Instance array, once in Destroy and a second time in Stop"
Those methods are commented out. Even when I uncommented `delete db3DResourceSupply` (leaving Destroy & Stop commented out) it continues to crash.

I'm sure I'm over looking something really simple.

Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 1st Jul 2009 12:36
I believe its something to do with your usage of the STL although I'm not exactly sure what without spending more time looking through your code. I cant get it to run in the debugger without spitting out an exception in regards to a template iterator in the template class <list> .. perhaps you are doing something illegal to an STL container somewhere ?

I can get it to run in release mode, but it crashes on exit as you describe. That is usually an indicator of some form of memory violation. Which means that the program is trying to delete something that has already been deleted or moved, most likely.

If it ain't broke.... DONT FIX IT !!!
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 1st Jul 2009 12:56
I didn't really look through the code but one thing to remember is if any of your destructors delete GDK objects or images and stuff you need to call them before your entry point is exited.

Michael P
18
Years of Service
User Offline
Joined: 6th Mar 2006
Location: London (UK)
Posted: 1st Jul 2009 22:35
Check that you're not trying to use object 0, that can cause memory corruption.

I doubt anyone will look through your code properly, so you're going to have to do it yourself.

A crash on exit doesn't necessarily mean there is something wrong with your destructors. If you make mistakes with memory, problems may appear well after the initial mistake. After fixing the initial bug Mista Wilson describes, I got a heap corruption error on exit. This is very hard to debug, the only way really is for you to look through all of your code and check each bit individually.

Since you don't seem to have noticed the initial bug Mista Wilson pointed out, it seems you don't have your project properties setup for debugging. If you are using the standard release settings because you got linker errors in debug, then change C++ -> Code Generation to Multi Threaded on the debug build, and you will have access to the normal debugging features.

TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 2nd Jul 2009 14:59
Quote: "I believe its something to do with your usage of the STL although I'm not exactly sure what without spending more time looking through your code. I cant get it to run in the debugger without spitting out an exception in regards to a template iterator in the template class <list> .. perhaps you are doing something illegal to an STL container somewhere ?"

I get the same error when I attempt to debug. But, I'm not versed in C++ to understand the template code I placed Breakpoints below the STL stack & list definitions to continue, shortly there after running into more exceptions. I even tried to bypass using STL stack with my own fifostack class. For the most part I'm copied code I found in examples found on www.cplusplus.com. I'll examine the stack code carefully and I'm open any to suggestions.

Quote: "but it crashes on exit as you describe. That is usually an indicator of some form of memory violation. Which means that the program is trying to delete something that has already been deleted or moved, most likely."


It runs and crashes on exit in debug mode for me.

Quote: "change C++ -> Code Generation to Multi Threaded on the debug build, and you will have access to the normal debugging features."
I'm using MT mode.

Quote: "If you make mistakes with memory, problems may appear well after the initial mistake. After fixing the initial bug Mista Wilson describes, I got a heap corruption error on exit. This is very hard to debug, the only way really is for you to look through all of your code and check each bit individually."

I wonder if the STL stack misuse has something to do with it. But, I'm not sure how im using the stack wrong because i basically copied the code changing the var names. I will triple check for object 0, if i can get the debugger to work.

Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 2nd Jul 2009 15:55
STL container can only be used in certain ways...

for example, a <queue> can only have items added to it at the end, and removed from the start, like a supermarket queue, a <dqueue> is a double ended version, a <vector> is like a dynamic array.

Which container you choose, and how you use it, depends on how you want to use it. Also, all of the STL classes contain their own management for reserving and freeing memory, so while you are using them, you dont need to worry about manually managing the memory for them.

I can think off the top of my head, but there are a few good sites and some good pages on MSN that detail using the STL and the best practices with it.

I can only suggest that you start small, get to know the containers and what you can and cant do with them, before you try to apply them.

Good luck though, it doesnt sound like you are too far away from a solution, you are definately on the right track.

If it ain't broke.... DONT FIX IT !!!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Jul 2009 22:38
My earlier guess was based on the destruction of the objects - I thought you'd commented it out simply as a part of the problem.

Anyway...


Arrays are zero-based. You are overwriting memory that doesn't belong to you.

If I were you, I'd rethink your design anyway - I'm confused as to why you need your own stack class, what the point of the d3dobject ans d3dresource classes is, why you are declaring everything as static in those and other classes ... and a lot more things TBH.

My advice would be one class to control the id numbers, one class for general object control (containing the id control class as a static), and a class each for Defender and Enzyme that each contain an object.

Take a look at the barely-started tutorial I posted for this about a year or so ago.

TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 6th Jul 2009 08:37 Edited at: 8th Jul 2009 00:17
Quote: "If I were you, I'd rethink your design anyway "


I've taken heed to the advice and reduced the number of classes etc. The app continues to crash after termination but, I believe I narrowed down the problem to how I'm using the STL list in the Enzyme methods. If I comment out Enzyme::update() the program terminates with no problems. I feel a fix is near. I trully appreciate everyone who has offered help.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 6th Jul 2009 15:55


Am I right in assuming that you already know Java? Because the way you are doing this is very Java-like, and 'not right' for C++.

Simply use the classes directly - don't hold pointers and new them, and then you also don't need to delete them.

Just use:


Oh, and you are still writing to memory that you don't own:


I'm not saying that's the only occurrence of this, but it's an obvious one.

TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 6th Jul 2009 16:47
Quote: "Am I right in assuming that you already know Java?"
Unfortunately, I don't know Java

Quote: "Oh, and you are still writing to memory that you don't own:"
I'm slightly confused. I declared the array and believe I have defined it. How do I own it?

AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 6th Jul 2009 16:48
Quote: "I declared the array and believe I have defined it. How do I own it?"


You're attempting to write to GameObject[2]. Because the indices of arrays in C++ start at 0, The highest index of GameObject is 1, so you can only write to GameObject[0] and GameObject[1].

i like orange
TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 8th Jul 2009 00:12 Edited at: 8th Jul 2009 00:16
Quote: "You're attempting to write to GameObject[2]. Because the indices of arrays in C++ start at 0, The highest index of GameObject is 1, so you can only write to GameObject[0] and GameObject[1]."


Thanks Everyone. As IanM & AndrewT indicated I was using Arrays improperly as they are 0 based. I desired to use them starting with index 1, I added + 1 to the declarations. Lesson Learned.

The Result


Login to post a reply

Server time is: 2024-10-01 06:03:21
Your offset time is: 2024-10-01 06:03:21