Archived

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

wolliwer

evil index buffers

Recommended Posts

I was playing with a way to draw terrain using index buffers that only represent small portions of the vertex buffer''s geometry. when i run the program it gets so far then restarts my computer. has anyone else encountered this problem? Is this because of index buffers? What''s going on!

Share this post


Link to post
Share on other sites
I am guessing your code is trying to write to memory it shouldn''t be accessing. This could be due to a rogue pointer or stepping beyond the bounds of an array.

Make sure your pointers are initialized and that you aren''t looping out beyond an array somewhere.

Use the debugger to set breakpoints and step into your code so that you know which piece of code is the offending beast.

Share this post


Link to post
Share on other sites
I had sort alike problems, and it took me about a week
to find out that the NumIndices parameters in the
DrawIndexedPrimitive is not the number of indices,
but the number of vertices.

Arie.

Share this post


Link to post
Share on other sites
thanks a lot for the responses. I will try to do that stuff.

To go into more detail into the problem, however. My terrain draws fine. I un-commented a debug line that draws all the vertices as points (which has worked before), that is when it first restarted my computer. Random things seem to set it off now, and the last time, it replaced my entire terrain.cpp file with a 29k of binary zeroes.

Anyway, about the number of vertices/indices thing Arie mentioned: I totally didn''t realize that, it may be the problem. That parameter is very misleading.

Share this post


Link to post
Share on other sites
I'm sort of trying to do the same thing as you, wolliwer... and having the same problem. But how do you get the number of vertices you use in your index buffer without adding tremendous overhead to your program (assuming your number of vertices is dynamic every time)? Wouldn't you have to scan the index array each time you add a new index to see if there's one like it already in the array, then if there is, not increment your vertex count? That's a lot of overhead... and I really don't want to use a data structure to speed it up... maybe I'm thinking too hard.

[edited by - Riskbreaker on October 20, 2002 3:49:14 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Riskbreaker
Wouldn''t you have to scan the index array each time you add a new index to see if there''s one like it already in the array, then if there is, not increment your vertex count?

No, you just keep count of how many vertices you added in there in the first place

I''m a bit sceptical about that parameter being so blatantly wrong though...



[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]

Share this post


Link to post
Share on other sites
Keeping track of the vertices is very easy. As Kylotan suggested, I just keep track of how many I have added from the begginning. The algoritm I use does not try to do any sort of dynamic indexing. The reason I''m splitting the mesh up into several index buffers instead of one is so that I don''t have to.

Basically, I take the terrain and split it up into ''grids'', a custom struct which holds an index buffer, number of vertices/polygons, etc. When the camera is first initialized, it calculates which index buffers need to be rendered to cover the screen, then as it is moved, it checks to see if that list needs to be updated. Because the index buffers are generated when the map is loaded there is practically no overhead at all once the terrain is up and running. In addition, it doesn''t give the GPU a lot of extra crap it doesn''t need to render because it''s not within the view.

Share this post


Link to post
Share on other sites
Additionally, now that I think of it, that wierd parameter kind of makes sense. I mean, if they meant the number of indices in the index list, that number would always be three times the number of polygons, which would be stupid to ask for as a separate parameter. If it means number of different vertices refrenced, that is information directx might need to know that it can''t easily get otherwise.

Share this post


Link to post
Share on other sites