Hey, folks.

I've got a weird problem with a bunch of arrays I'm allocating on the free store.

Before I post any code, let me just explain the general situation and maybe someone can tell me if I'm on the right track.

Basic idea:
Allocate arrays of objects to be used for characters etc. during a game. Each level needs its own arrays for the characters etc. of that level.

So, when you advance a level,
a) old arrays are deleted
b) new arrays are established.

Also, when you start a new game (because you messed up or something and just want to start over) the arrays are deleted and everything is set up again.

I'm at the point in developing the game where I can't move forward until I get the level-advance mechanism working.

So here's the problem.

1). I declare one-dimensional arrays on the free store and use them during the course of the game.

2) When the level's over (or, right now, when I choose to start over) I delete the arrays using delete[].

First observation: My compiler, which is either the Cygwn or Mingw compiler under Dev-C++ 4, issues a warning that I'm deleting these arrays, like so:

506 c:/program files/gmmain.cpp
warning: deleting array `class Junction * pJunctionArray[(gNumJunctions + 1)]'

Now, I don't see why I should get warnings here since delete[] is a perfectly ordinary process, no?

And here's the abyss of the problem itself.

I have the game set up so when you close it (click the X) you get a dialog box which gives some options, one of which is to restart the game. So, to test out this deallocate/reallocate business I sat there and kept restarting the game over and over. I won't get into why I already suspected there'd be a problem , but I'm glad I kept hitting the restart button because it's only after the 20th or even 30th restart that the program finally does what the Titanic does best, and plunges inexplicably into the depths.

What's going on here!??? I thought that maybe the deallocate wasn't working and I was running out of memory, so I added a routine to catch an out-of-memory error, but that turned up nothing. So what's going wrong?

If the game successfully restarts 30 times, why not 31 times? Why not 1031 times? Eh eh eh??? What is hap-hap-happenning in the hidden gremlins of my computer?

My delete[] should work!

If I declare an array of objects on the free store, and then delete them, can't I then use that same pointer to an array and fill it up with new objects?

Do I have to set that pointer (those pointers?) to null before I use it again, or what?

Bottom line: How do I put an array of objects on the free store, get rid of them, and then put them back?

I'll put up some code if you don't get what I'm saying, just tell me what you want to see.

I really need to sort this out to build new levels in my game! The frustrating thing is it almost works! If I sort this out the rest is easy sailing.