Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

I suck at delete

Name: Anonymous 2008-10-22 15:48

So it seems I don't know how to use delete properly in C++. I have a "Matrix" class that dynamically allocates memory for a 2D array of floats, and I'm creating and destroying tonnes of these as the application runs. So I put this in the destructor.


for(GLuint i = 0 ; i < height ; i++)
  delete matrix[i];


It crashes instantly.

Here is the matrix variable:

GLfloat **matrix;


And here is the code setting up the matrix:

matrix = new GLfloat*[height];
for(GLuint i = 0 ; i < height ; i++){
  matrix[i] = new GLfloat[width];
  for(GLuint j = 0 ; j < width ; j++){
    matrix[i][j] = (i == j && isIdentity ? 1 : 0 );
  }
}


Wtf is my stupid ass doing wrong?

Name: Anonymous 2008-10-22 18:37


>>10
1) Programs always act the way the programmer told them to do, they don't have any ``mistake'' in THEM.
2) Don't learn OpenGL before knowing the basis
3) Doing something like new GLFloat[width][height]; is allowed in Sepples
4) I hope you realize you're assigning a boolean to a GLFloat without performing any typecast
5) See >>8,9
AND FUQIN LASTLY
isIdentity ? 1 : 0
THIS IS THE MOST USELESS PIECE OF CODE EVER WRITTEN


IHBT

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List