I get this eror from Visual C ++:
HEAP [ShockRay3.exe]: heap block in 00557018, changed to 00557044, last requested size 24
This happens when I add a line of code between two recursive calls in a function. The entire line of code makes this pointer change, but for some reason, every time I insert it, I get this error.
This is a simplified version of the code (only memory heap memory calls a function)
int KDTree::BuildBranch(int height, Mailbox** objs, int nObjects)
{
{...}
if(height == -1 || nObjects < minObjectsPerNode)
{
{...}
return nodeIndex - 1;
}
BoundingBox* tempBox = new BoundingBox();
if(nodeIndex == 1)
{
{...}
for(int i = 0; i < nObjects; i++)
{
objs[i]->prim->MakeBoundingBox(tempBox);
xMins[index] = tempBox->x0;
yMins[index] = tempBox->y0;
zMins[index] = tempBox->z0;
xMaxs[index] = tempBox->x1;
yMaxs[index] = tempBox->y1;
zMaxs[index] = tempBox->z1;
index++;
}
}
else
{
for(int i = 0; i < nObjects; i++)
{
objs[i]->prim->MakeBoundingBox(tempBox);
if(tempBox->x0 < curVoxelBounds->x0)
{
{...}
}
else
{
xMins[xMinCount] = tempBox->x0;
{...}
}
if(tempBox->y0 < curVoxelBounds->y0)
{
{...}
}
else
{
yMins[yMinCount] = tempBox->y0;
{...}
}
if(tempBox->z0 < curVoxelBounds->z0)
{
{...}
}
else
{
zMins[zMinCount] = tempBox->z0;
{...}
}
if(tempBox->x1 > curVoxelBounds->x1)
{
{...}
}
else
{
xMaxs[xMaxCount] = tempBox->x1;
{...}
}
if(tempBox->y1 > curVoxelBounds->y1)
{
{...}
}
else
{
yMaxs[yMaxCount] = tempBox->y1;
{...}
}
if(tempBox->z1 > curVoxelBounds->z1)
{
{...}
}
else
{
zMaxs[zMaxCount] = tempBox->z1;
{...}
}
}
}
if(nodeIndex == 1)
{
bb = new BoundingBox(xMins[0], xMaxs[nObjects - 1], yMins[0], yMaxs[nObjects - 1], zMins[0], zMaxs[nObjects - 1]);
curVoxelBounds = new BoundingBox(xMins[0], xMaxs[nObjects - 1], yMins[0], yMaxs[nObjects - 1], zMins[0], zMaxs[nObjects - 1]);
}
{...}
Mailbox** leftList = new Mailbox*[minLeftCounter];
Mailbox** rightList = new Mailbox*[minRightCounter];
BoundingBox* rightBox = NULL;
BoundingBox* leftBox = NULL;
BoundingBox* savedBox = curVoxelBounds;
int leftIndex = 0, rightIndex = 0;
{...}
switch(axis)
{
case 0:
for(int i = 0; i < nObjects; i++)
{
objs[i]->prim->MakeBoundingBox(tempBox);
if(tempBox->x0 < splitLoc)
{
{...}
}
if(tempBox->x1 > splitLoc)
{
{...}
}
}
leftBox = new BoundingBox(curVoxelBounds->x0, splitLoc, curVoxelBounds->y0,
curVoxelBounds->y1, curVoxelBounds->z0, curVoxelBounds->z1);
rightBox = new BoundingBox(splitLoc, curVoxelBounds->x1, curVoxelBounds->y0,
curVoxelBounds->y1, curVoxelBounds->z0, curVoxelBounds->z1);
break;
case 1:
for(int i = 0; i < nObjects; i++)
{
objs[i]->prim->MakeBoundingBox(tempBox);
if(tempBox->y0 < splitLoc)
{
{...}
}
if(tempBox->y1 > splitLoc)
{
{...}
}
}
leftBox = new BoundingBox(curVoxelBounds->x0, curVoxelBounds->x1, curVoxelBounds->y0,
splitLoc, curVoxelBounds->z0, curVoxelBounds->z1);
rightBox = new BoundingBox(curVoxelBounds->x0, curVoxelBounds->x1, splitLoc,
curVoxelBounds->y1, curVoxelBounds->z0, curVoxelBounds->z1);
break;
case 2:
for(int i = 0; i < nObjects; i++)
{
objs[i]->prim->MakeBoundingBox(tempBox);
if(tempBox->z0 < splitLoc)
{
{...}
}
if(tempBox->z1 > splitLoc)
{
{...}
}
}
leftBox = new BoundingBox(curVoxelBounds->x0, curVoxelBounds->x1, curVoxelBounds->y0,
curVoxelBounds->y1, curVoxelBounds->z0, splitLoc);
rightBox = new BoundingBox(curVoxelBounds->x0, curVoxelBounds->x1, curVoxelBounds->y0,
curVoxelBounds->y1, splitLoc, curVoxelBounds->z1);
break;
};
delete tempBox;
delete[] objs;
{...}
curVoxelBounds = leftBox;
BuildBranch(height - 1, leftList, leftCount);
curVoxelBounds = rightBox;
int rcNodeIndex = BuildBranch(height - 1, rightList, rightCount);
curVoxelBounds = savedBox;
delete leftBox;
delete rightBox;
{...}
return thisNodeIndex;
}
If I take this line where I change the pointer, the program works. If I leave it, it does not work, and the call stack shows this line:
delete[] objs;
but before that, in the call stack, this is the line that apparently calls it. I do not know how changing a pointer can transcode the code to this delete line.