• Create Account

### #ActualDanicco

Posted 28 December 2012 - 02:53 PM

I have this code:



unsigned char *bitmapArray = new unsigned char[imageWidth * imageHeight * 4]; //array with enough values for RGBA of the BMP

int c = 0;
{

//Filling RGBA info into my bitmapArray
bitmapArray[c] = pixeInfo[0];
bitmapArray[c + 1] = pixeInfo[1];
bitmapArray[c + 2] = pixeInfo[2];
bitmapArray[c + 3] = 255;
c += 4; //increasing C for the next values
}

//Here I use bitmapArray for some stuff

delete[] bitmapArray; //This gives me HEAP CORRUPTION error

If I don't mess with bitmapArray inside the while loop (simply commenting 4 lines, still leaving the reader there), it goes through fine.

The size of the image I'm using is 40000 bytes long, if I declare the array as "unsigned char bitmapArray[40000];" I still get the same error, but if I add a single char it doesn't - "unsigned char bitmapArray[40001];"

I checked the address the debugger says it's corrupted, but it isn't nowhere close to the starting/ending addresses of bitmapArray.

The error is: "HEAP CORRUPTION DETECTED: after Normal block (#161) at 0x00413F58. CRT detected that the application wrote to memory after end of heap buffer."

Why is this happening?

### #1Danicco

Posted 28 December 2012 - 02:28 PM

I have this code:

ifstream reader;

unsigned char *bitmapArray = new unsigned char[imageWidth * imageHeight * 4]; //array with enough values for RGBA of the BMP

int c = 0;
{

//Filling RGBA info into my bitmapArray
bitmapArray[c] = pixeInfo[0];
bitmapArray[c + 1] = pixeInfo[1];
bitmapArray[c + 2] = pixeInfo[2];
bitmapArray[c + 3] = pixeInfo[3];
c += 4; //increasing C for the next values
}

//Here I use bitmapArray for some stuff

delete[] bitmapArray; //This gives me HEAP CORRUPTION error

If I don't mess with bitmapArray inside the while loop (simply commenting 4 lines, still leaving the reader there), it goes through fine.

The size of the image I'm using is 40000 bytes long, if I declare the array as "unsigned char bitmapArray[40000];" I still get the same error, but if I add a single char it doesn't - "unsigned char bitmapArray[40001];"

I checked the address the debugger says it's corrupted, but it isn't nowhere close to the starting/ending addresses of bitmapArray.

The error is: "HEAP CORRUPTION DETECTED: after Normal block (#161) at 0x00413F58. CRT detected that the application wrote to memory after end of heap buffer."

Why is this happening?

PARTNERS