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!
FOR loop acting strange
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]
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]
crispy is correct.
0..199 is 200 units across, "0" represents the first element, while 199 represents the 200th (last) element
so "< 200" should work, but not "< 201".
www.cppnow.com
0..199 is 200 units across, "0" represents the first element, while 199 represents the 200th (last) element
so "< 200" should work, but not "< 201".
www.cppnow.com
I''ve already answered it for you on IRC, but bleh:
The condition section of your
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]
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 ]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement