Weird "HEAP CORRUPTION DETECTED: after Normal block" error when attempting to delete array...

Hello,

I posted a yesterday about creating and deleting arrays but my example program worked fine when corrected while the problem I have with my larger program remains.

Essentially I am trying to delete a float array I created in memory but I get the "HEAP CORRUPTION DETECTED: after Normal block" error when I do so.

I know that the array is valid because as a test in the destructor for the class I do a stupid loop through the values in the to-be-deleted array with no problem like so:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

/*

This code 100% works in the destructor for the class.

Note: I know the array has 24 elements as in this case it is a fixed size I create in the constructor.

*/

for (int i = 0; i < 23; ++i) {

	GLfloat CurrentValue = ArrayValues[i];
	CurrentValue = CurrentValue;

}

/*

I get the "HEAP CORRUPTION" error when trying to delete this valid array.

*/

delete [] ArrayValues;


Anyone knows the reason I would get the error for a valid array?

Thank you.
Last edited on
First, realize that your for loop is essentially doing nothing useful, as far as I can tell. You create local variable and then do nothing with that local variable (assign it to itself).

Where do you define and initialize your ArrayValues pointer? I think more relevant code needs to be shown.
Last edited on
Correct, the loop was something stupid to verify that array was indeed valid and I used the debugger to see if "CurrentValue" had the value of the ArrayValue element indicated by "i" in the loop,

I initialize the ArrayValues pointer like so:

In the header file:

 
GLfloat* ArrayValues;


Class constructor:
 
ArrayValues = new GLfloat[23];


At first glance at the code given, I see nothing wrong. It must be a combination of something else, sorry wish I could help more. Not sure if opengl's float is doing something weird behind the scenes.
Topic archived. No new replies allowed.