Jump to content
  • Advertisement
Sign in to follow this  
MARS_999

Dynamic MultiDim arrays with Structures

This topic is 4745 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am having an issue with my dynamic 2 dim array thats a struct.
struct Vertex
{
	float vx;
	float vy;
	float vz;
	float nx;
	float ny;
	float nz;
	float tx;
	float ty;
};

//this is declared in a class
Vertex **terrain;

//now in my constructor
terrain = new Vertex*[mapData.map_Z];
	for(z = 0; z < mapData.map_Z; z++)
	terrain[z] = new Vertex[mapData.map_X];

I am getting this message error Access violation writing location 0xfdfdfdfd. So I am led to believe I am not allocating something right...

Share this post


Link to post
Share on other sites
Advertisement
Where does the access violation occur? Whilst allocating the array(s) or later on access? The code you have is correct (except for the lack of exception safety). Probably you have memory errors elsewhere in your code, especially if this is not the only place you are taking the responsibility for memory management yourself by using new instead of a managed array such as std::vector.

For this situation you may consider alternatives like a vector of vectors, a single vector indexed by (y * width) + x, a Boost.MultiArray, or another suitable container.

Enigma

Share this post


Link to post
Share on other sites
Quote:
Original post by Enigma
Where does the access violation occur? Whilst allocating the array(s) or later on access? The code you have is correct (except for the lack of exception safety). Probably you have memory errors elsewhere in your code, especially if this is not the only place you are taking the responsibility for memory management yourself by using new instead of a managed array such as std::vector.

For this situation you may consider alternatives like a vector of vectors, a single vector indexed by (y * width) + x, a Boost.MultiArray, or another suitable container.

Enigma


I find it. I had the data set to zero for the size... But on another note. The data in my vertex struct is all auto variables. So if I am using a dynamic array of vertex do I need to change my floats in the vertex struct to make them dynamic also or can I leave them as autos...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!