Here is my function:
void Tetris::place_square(int* coords,char type){
if (coords[1]>heights[coords[0]]){
char* old=data[coords[0]];
data[coords[0]]=new char[coords[1]];
for (unsigned int i=0; i<heights[coords[0]]; ++i){
data[coords[0]][i]=old[i];
}
for (unsigned int i=heights[coords[0]]; i<coords[1]; ++i){
data[coords[0]][i]=" "[0];
}
data[coords[0]][coords[1]-1]=type;
heights[coords[0]]=coords[1];
delete old;
} else {
data[coords[0]][coords[1]-1]=type;
}
}
It compiles fine but when I try to run it i get malloc: *** error for object 0x7fff503e0020: pointer being freed was not allocated
I believe the problem is delete old;
but I don't know how to fix it.