Sign in to follow this  

[MDX] - Creating Mesh error when face count is too high - "Error in Application"

This topic is 4215 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 creating a mesh to render a terrain which works fine with the below code unless the map size is above around 85x85 (which works out to around 15k faces). The error message isn't giving much away though so I'm stumped. Is there a restriction on the number of faces a mesh can have?

int iFaces = (MapWidth - 1) * (MapHeight - 1) * 2;

Mesh meshTerrain = new Mesh(
    iFaces,
    iFaces * 3,
    MeshFlags.Managed,
    Position2Textured.Format,
    device
);


I have tried this code with the Apr2005 and Apr2006 SDKs. Same effect in both. Thanks

Share this post


Link to post
Share on other sites
Are you getting any debug runtimes warnings/messages?

Bare in mind that large chunks of geometry can hit the draw-call limit and/or the index size limit. Move than 65,536 vertices requires a 32bit index buffer - even then that doesn't mean you can use all 4.2bn vertices a 32bit index buffer can address (my GeForce 6800 can only handle ~16.7 million)...

If I am correct then are you sure its only 85x85 and above? you should be able to handle much higher than that with a 16bit buffer...

hth
Jack

Share this post


Link to post
Share on other sites
Jack,

I received no complaints ast run time at all. I just get the exception and the inpsecting it gives me no further information. Not very helpful.

I only know that it doesn't work above 15k faces because I kept plugging in a value until it worked. I started at 40000, which would allow me around 140x140, which didn't work. It only worked at 15000 or so, which is about 85 given the above expression for iFaces.

At this stage I haven't associated any index buffer with the mesh so the index size shouldn't be a factor.

I know the card can handle much more than 85x85 since I am able to build a terrain using just index/vertex buffers (no mesh) up to 200x200 - it doesn't run above 10fps, but it does run!

Thanks for your input - much appreciated.

Share this post


Link to post
Share on other sites
Jack,

I had another go at that Mesh constructor with a slight change to the face and vertices count:



meshTerrain = new Mesh(
indices.Length / 3,
vertices.Length,
MeshFlags.Managed,
Position2Textured.Format,
_device
);



and this has worked on a larger height map - now 128x128. Don't know why though!

This brings me to my next question, one which you've already mentioned:

I can't seem to build a mesh much bigger than that, probably due to the limit on the index buffer (im using a short[] structure for indexes). How does one build a larger terrain? Would I be best to chain multiple terrain meshes together each forming a section of the map, or do I need to implement a LOD algorithm?

I have done some reading up on LODs and don't think there is much content for C# coders. Any tips?

Thanks for your assistance.


Share this post


Link to post
Share on other sites
Going much bigger than 128x128 starts losing it's point.

Since only part of the terrain will ever be visible, you'll want ways of only drawing a certain portion of the terrain.

The smaller the blocks you use, the less terrain that is out of the view area you'll need to draw (aka overdraw). However, if you make the patches smaller, they'll require more SetStreamSource calls to change buffers (this is a call the Mesh class calls internally).

So, it's a balance thing, but 128x128 is pretty big. I'd recommend you stick several meshes next to eachother, and select only those in view to draw.

As for LOD, you'd probably need to use straight vertex and index buffers for that, since the Mesh interface isn't that flexible.

Share this post


Link to post
Share on other sites

This topic is 4215 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this