As Matty said, it's usually related to a memory corruption. The reason why it doesn't happen in debug mode is because the debug library allocates a bit of extra memory for you at every request. When you request, say - 10-bytes of memory, you will actually receive 10-bytes plus some extra buffer space at the end. The extra buffer space is a "just in case" thing so that if you over-run your buffer, it won't necessarily blow up on you when you're running the debug build. However, it should inform you that you over-ran the buffer - via a call to OutputDebugString() I believe.
I see that you use alot of arrays in your code. So I would start there. Look for something like:
#define ARRAY_SIZE 100
int SomeIntArray[ARRAY_SIZE];
for (int x=0; x<=ARRAY_SIZE; x++) {
SomeIntArray[x]=0; // Gotcha if x==ARRAY_SIZE... remove the equal-sign
}
A more subtle bug, and probably more applicable to your case now that I took another look at your code, is such:
I see that you call delete [] quite a bit. The problem is that you are not checking to see if there really is something to delete [] first. You should do a check for NULL first as in:
#define NULL 0L // Should be defined already by windows...
if (some_ptr==NULL)
delete [] some_ptr;
Fortunately, GDK has the above snippet already wrapped up into a nice little macro:
SAFE_DELETE_ARRAY(some_array_ptr);
SAFE_DELETE(some_ptr);
Now why would this be more subtle you ask? Because in Debug mode, any value that you don't intialize will default to something. Pointers will default to NULL. In Release mode, no such default initialization takes place. Because if this, it's best if you initialize everything yourself all of the time. That way you have a known state to work from. The following code is not the same between debug and release:
In debug build, pInt=NULL but in release build, pInt=??? (whatever value is already in that location). In this case, the SAFE_DELETE() macro would see a value other than NULL in pInt and continue with the delete operation - Gotcha!
Instead, use this code:
This time we've initialized the value ourself to a known state (NULL) and SAFE_DELETE() would not attempt to perform the delete operation unless we've actually made a change.
I hope this gives you some guidance on what to look for. Be warned though, it may be tough to spot!
Regards,
JTK
Edit: Added SAFE_DELETE() / SAFE_DELETE_ARRAY() distinction.