Alright, I'm trying to make a dynamic array.
The concept itself works. I can delete certain elements of the array just fine, but when I add to the array... I get garbage in spots that I know shouldn't have garbage.
Right after expanding the array, I have it throw debug info to the screen SPECIFICALLY saying that the part of my array with data still HAS that data... but then it immediately goes away!
Here's the code that does just that:
#include "DarkGDK.h"
struct mytype {
int h;
};
mytype* typarray = NULL;
int max = 10;
// the main entry point for the application is this function
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
dbDisableEscapeKey ( );
typarray = new mytype[max];
typarray[8].h = 1000;
int oktopress = 0;
while ( LoopGDK ( ) )
{
if (dbSpaceKey() == 1 && oktopress == 1) {
//Make temporary array
mytype* temp = new mytype[max++];
//Fill temp array
for (int i = 0; i<max-1; i++) {
temp[i] = typarray[i];
}
//Resize our array
delete [] typarray;
mytype* typarray = new mytype[max];
//Refill our array
for (int i = 0; i<max-1; i++) {
typarray[i] = temp[i];
}
//
// RIGHT HERE, The text displayed SHOWS the [8].h has 1000 in it.
dbInk(dbRGB(255,255,0),0);
dbText(0,0,dbStr(typarray[8].h));
dbSync();
dbWaitKey();
// But as soon as it goes back to looping, [8].h gets garbage thrown in it!! :'(
//Delete our temp array
delete [] temp;
oktopress=0;
}
if (dbSpaceKey()==0)
oktopress=1;
if ( dbEscapeKey ( ) )
break;
dbInk(dbRGB(255,255,0),0);
dbText(0,0,dbStr(typarray[8].h));
dbText(0,10,dbStr(max));
dbSync ( );
dbCLS(0);
}
return;
}
Does anyone see something wrong here that I'm missing?
The one and only,