Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


#ActualParadigm Shifter

Posted 02 August 2013 - 09:22 AM

The way you use vertexData (allocate it with new[], then add stuff to it, then subtract what you added to it before calling delete[] vertexData) is just asking for trouble, just make a copy of the pointer if you are going to manipulate it.

 

I'd do something like this:

 

byte* vertexData = new byte[bufferSize];

float* floatArray = reinterpret_cast<float*>(vertexData);

 

// do stuff with float array, no need to keep adding sizeof(float) either when you work with floatArray, just use ++floatArray. Don't ever change the value of vertexData

 

delete[] vertexData;

 

EDIT: Whoops ;)


#2Paradigm Shifter

Posted 02 August 2013 - 09:21 AM

The way you use vertexData (allocate it with new[], then add stuff to it, then subtract what you added to it before calling delete[] vertexData) is just asking for trouble, just make a copy of the pointer if you are going to manipulate it.

 

I'd do something like this:

 

byte* vertexData = new byte[bufferSize];

float* floatArray = reinterpret_cast<float*>(vertexData);

 

// do stuff with float array, no need to keep adding sizeof(float) either when you work with floatArray, just use ++floatArray. Don't ever change the value of vertexData

 

delete[] vertexData;


#1Paradigm Shifter

Posted 02 August 2013 - 09:18 AM

The way you use vertexData (allocate it with new[], then add stuff to it, then subtract what you added to it before calling delete[] vertexData) is just asking for trouble, just make a copy of the pointer if you are going to manipulate it.

 

I'd do something like this:

 

byte* vertexData = new byte[bufferSize];

float* floatArray = reinterpret_cast<byte*>(vertexData);

 

// do stuff with float array, no need to keep adding sizeof(float) either when you work with floatArray, just use ++floatArray. Don't ever change the value of vertexData

 

delete[] vertexData;


PARTNERS