I've [attempted] to implement a two dimensional array, for a zBuffer as follows:
struct Properties {
....
double** zBuffer;
....
}
Here's where it's used:
void initializeZBuffer(Properties* props){
//Destroy old zBuffer 2D array (if it's already been initialized)
if (sizeof props->zBuffer[0] >= 0){
for (int i = 0; i < props->clientRect.Height(); i++){
delete[] props->zBuffer[i];
}
delete[] props->zBuffer;
}
//Create new zBuffer 2D array
props->zBuffer = new double*[props->clientRect.Height()]; //zBuffer height x width
for (int i = 0; i < props->clientRect.Height(); i++){
props->zBuffer[i] = new double[props->clientRect.Width()];
}
}
My goal is to create an array that holds a z
value for every x
y
pixel on the screen.
The problem in my code is: I check to see if the array has any data in it - it shouldn't on the first iteration, but it does. For some reason, every slot holds a size of 4.
For example, when debugging at that point:
sizeof props->zBuffer[1] -----> returns 4
sizeof props->zBuffer[100] -----> returns 4
sizeof props->zBuffer[1000000] -----> returns 4
sizeof props->zBuffer[10000000000] -----> returns 4
and
sizeof props->zBuffer[1][1] -----> returns 4
sizeof props->zBuffer[100][100] -----> returns 4
sizeof props->zBuffer[1000000][1000000] -----> returns 4
sizeof props->zBuffer[10000000000][10000000] -----> returns 4
Since it has a size of 4, naturally I try to see what's in props->zBuffer[3]
(the last slot), but I get an error that
ds->zBuffer[3]
CXX0030: Error: expression cannot be evaluated
Does anyone have any clue what is going on? I am totally baffled and frustrated :(