I encountered this problem many times but now i don't know what to do
basically i create a set of object with new operator
like:
Items = new TFileItem[ Count ];
TFileItem is a strcuture
struct TFileItem
{
bool isDir;
AnsiString name;
TGLTexture thumbnail;
float x;
float y;
float w;
float h;
TFileItem()
{
isDir = false;
name = "";
}
~TFileItem()
{
return;
if (!isDir)
thumbnail.~TGLTexture();
}
};
THEN THE MIGHTY HEAP CORRUPTION COMES.
whenever i try to
delete [] Items;
i get this:
void Update()
{
ican = false;
ProcessUpdate = false;
if (Items != NULL)
{
ALOG("DELETE VBUFF AND ITEM ARRAY");
delete [] Items;
ALOG("ITEMS DELETED");
delete [] VBUFF;
ALOG("DONE now null items");
Items = NULL;
ALOG("DELETE BUFFERS");
glDeleteBuffers(1, &item_vbuff);
ALOG("OK MAKE NEWE ARRAYS AND ENLIST");
}
Count = s->Count + d->Count;
LastCount = Count;
Items = new TFileItem[ Count ];
VBUFF = new TFileItemVertex[ Count * 4 ];
ALOG("LIST dirs: found: "+IntToStr(d->Count) +" all items: "+IntToStr(Count));
int cnt = -1;
for (int i=0; i < d->Count; i++) //First enlist directories
{
cnt = cnt + 1;
Items[cnt].thumbnail = dir_thumbnail;
Items[cnt].name = d->Strings[i];
Items[cnt].isDir = true;
}
ALOG("LISTING FILES: items: "+IntToStr(s->Count));
for (int i=0; i < s->Count; i++) //secondly enlist files
{
cnt = cnt + 1;
Items[cnt].thumbnail.LoadTGA(Directory+s->Strings[i]);
Items[cnt].name = s->Strings[i];
}
float sw = float(SCREEN_WIDTH);
float sh = float(SCREEN_HEIGHT);
float item_width = (width*sw) / float(row_items);
space_width = (item_width*0.2) / float(row_items+1.0);
real_item_width = ((width*sw) - space_width*float(row_items+1.0) ) / float(row_items);
for (int i=0; i < Count; i++)
{
int row = int( float(i) / float(row_items) );
max_row_counted = row;
int item_num = i % row_items;
//number of spaces between items is always number_of_items per row + 1
PlaceItem(x*sw + space_width + (space_width+real_item_width)*float(item_num),
0.0, real_item_width, real_item_width, VBUFF, Items, i, sw, sh );
//((y+height)*sh - space_width) - float(row)*(space_width*3.0 + real_item_width)
}
rows_in_window = int((height*float(SCREEN_HEIGHT)) / (space_width*3.0 + real_item_width));
ALOG("space_width: "+FloatToStr(space_width));
ALOG("real_item_width: "+FloatToStr(real_item_width));
ALOG("height: "+FloatToStr(height));
ALOG("AVAIL ROWS IN WINDOW: "+IntToStr(rows_in_window));
glGenBuffers(1, &item_vbuff);
glBindBuffer(GL_ARRAY_BUFFER, item_vbuff);
glBufferData(GL_ARRAY_BUFFER, sizeof(TFileItemVertex) * 4 * Count, VBUFF, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
ALOG("VBUFF 0: "+POINT_TO_TEXT(VBUFF[0].v));
ALOG("VBUFF 1: "+POINT_TO_TEXT(VBUFF[1].v));
ALOG("VBUFF 2: "+POINT_TO_TEXT(VBUFF[2].v));
ALOG("VBUFF 3: "+POINT_TO_TEXT(VBUFF[3].v));
ican = true;
}
Log reports only:
DELETE VBUFF AND ITEM ARRAY