malloc access problem
when compiled says: "Access violation writing location" on the HenonList.x = 5; line
float x, y, z; // Position of vertex in 3D space
RGBquad color; // Color of vertex
HenonList = (Vertex*)malloc(rits * sizeof(Vertex*));
if(HenonList == NULL) exit(1);
HenonList.x = 5;
But I don't understand how come? I malloc'd correctly right?
You are asking for memory to hold rits # of Vertex pointers. What you probably want is rits # of whole Vertex objects.
Why use malloc instead of new?
If this is really C, then don't cast malloc.
We don't know what "rits" is - if it is less than 900, then the rest of the malloc is irrelevant.
But I guess that your actual problem is that you are using sizeof(Vertex*) rather than sizeof(Vertex) or sizeof(*HenonList).
Since sizeof(Vertex *) is the size of a pointer, it is likely much smaller than the x, y, z and RGQQuad values.
Also, since this is C++, you should probably use
That way, you don't need a cast for malloc, and you don't need to worry about getting any sizeof right. Just remember to use delete  to delete the value after you finish.
Vertex *HenonList = new Vertex[rits];
Hey, thank you VERY much with your responces!
You were EXACTLY right, I didn't catch it until now lol
And your right, I should be using the new function instead. I will work on converting the code now
- Again, Thank you very much
Just remember that in modern C++, new never returns NULL, if it cant fill the memory request, it throws an exception instead. For the most part, all this means is that you don't need to check for NULL. You don't necessarily have to try catching this exception either, but if you do, just a single catch around the contents of main should be fine.
Originally Posted by parad0x13
There's also a way of calling a "no throw" version of new, for compatibility with older code you could say, but I'd just go for the normal 'new' here if you can.