Archived

This topic is now archived and is closed to further replies.

Xtremehobo

FOR loop acting strange

Recommended Posts

    CUSTOMVERTEX m_Vertices[40000];
	long vcount=0;
    for(int x=0;x<201;x++)
	{
		for(int z=0;z<201;z++)
		{
			m_Vertices[vcount].x     = x;
			m_Vertices[vcount].y     = Heightmap[x][z];
			m_Vertices[vcount].z     = z;
			m_Vertices[vcount].color = 0xffffffff;
			m_Vertices[vcount].tu    = 1;
			m_Vertices[vcount].tv    = 1;
			vcount++;
		}
	}
When I try to run this code, I get an access error, so I run it in debug mode and check the value of vcount and its 1128726528 which seems to be impossible for two nested for loops that go up to 100 to reach. The max that vcount can reach should be 40,000 shouldn''t it? Anyways, why is this code giving me an access error. Specifically , it points to the line "m_Vertices[vcount].y = Heightmap[x][z]; but I''m kinda thinking the problem with vcount is causing it.. Thanks ----- GSACP: GameDev Society Against Crap Posting To join: Put these lines in your signature and don''t post crap!

Share this post


Link to post
Share on other sites
the loop doesn't go up to 201 though.. it only reaches 200 (hence the x<201)

EDIT: nevermind, that solves it! (and about another 100 c++ problems I've had in the past)
lol thanks

[edited by - Xtremehobo on July 3, 2003 1:33:04 PM]

Share this post


Link to post
Share on other sites
I''ve already answered it for you on IRC, but bleh:

The condition section of your for loops should be "x < 200", as you wish to loop through 200 * 200 (40,000) of the arrays elements. As you have got it, it is looping round 201 * 201 (40,401) times.

[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]

Share this post


Link to post
Share on other sites