Jump to content
  • Advertisement
Sign in to follow this  
ibelchamber

problems with Mesh.TextFromFont

This topic is 4819 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

My application draws a number of items on each render(nothing unusual about that), at the moment, the items are represented by objects which contain meshes, and I'm destroying then redefining all my objects on each render. I'll probably improve this, but I want to understand the problem I have now incase I end up just "hiding" it. Each item can have text associated with it, this is held in a mesh variable in my object. Each time I create the objects, I create any text there may be with: mesh3DText = Mesh.TextFromFont(Device3D, SelFont, MText, 1.0F, 0.1F) When I destroy the object, I call: mesh3DText.Dispose() But something is wrong: The app runs unreliably, and quite quickly fails, normally with an "out of memory" error. If I comment out the line that creates the text mesh, everything runs fine (but I get no text of course) If I create a teapot instead of a text mesh, everything runs fine, but a bit slower as I think the teapot meshes are much bigger than my small text meshes. I've even tried forcing the text to just "." to keep the mesh really small, but it's just as unreliable. Should it work ok if I call the above 2 lines many times to create and destroy a text mesh? Why is it going wrong with a text mess and not a larger teapot mesh? Any help much appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by ibelchamber
... I'm destroying then redefining all my objects on each render.


Not surprising that you get an out of memory error. Don't do this. It will make your code very very slow and error prone. Re-structure you code so that you only make the meshes that you need at the beginning or the first time you need them. Keep them around and use them to render, destroying them when the application is done or you are sure your will not be using them again.



Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Like I said, I know this needs to be optimised, but in principle, as far as I can see I am managing the resource correctly, destroying it after using it, and this should not result in memory problems. I suspect that if I improve the code as you mention, the problem may not occur, but to me this is hiding a problem, not properly understanding and solving it.

I may need to display text which is changing, which would force me to destroy and remake meshes many times during the application runtime. It should be possible to do this without the problems I have seen.

Thanks

Share this post


Link to post
Share on other sites
(sorry, this was in response to turnpast)

Like I said, I know this needs to be optimised, but in principle, as far as I can see I am managing the resource correctly, destroying it after using it, and this should not result in memory problems. I suspect that if I improve the code as you mention, the problem may not occur, but to me this is hiding a problem, not properly understanding and solving it.

I may need to display text which is changing, which would force me to destroy and remake meshes many times during the application runtime. It should be possible to do this without the problems I have seen.

Thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by ibelchamber
I may need to display text which is changing, which would force me to destroy and remake meshes many times during the application runtime. It should be possible to do this without the problems I have seen.

Thanks


Yes to do this without the problems you have seen you will have to come up with a smart way of handing your meshes. For text you can pre-generate the meshes for a character set/font then draw/position these pre-generated meshes every frame. Unless you are really going wild with chnaging the font this should work just fine. This sort of thing is not an optimization, but a necessity. Creating and destroying complicated meshes every frame will be probihitively slow and resource consuming -- in other words it will not work.

If you do in fact have dynamic data that you cannot make static you will have to do more code work beforehand and every frame to handle the limits imposed by the hardware.

Share this post


Link to post
Share on other sites
Thanks for the ideas to make things better, but I'd really like to understand: is there a fixed limit to the number of times meshes can be created and destroyed, and if so, how can you find out what it is, in order to be certain that you don't exceed it?

Also, I saw a performance problem creating and destroying much larger teapot meshes, but it ran for hours without a problem. My smaller text meshes actually ran adequately fast, but with the memory problems mentioned. I still think there is something happening which needs to be understood, in order to have confidence that what I do will overcome it.

Thanks.

Share this post


Link to post
Share on other sites
Quote:
Original post by ibelchamber
is there a fixed limit to the number of times meshes can be created and destroyed, and if so, how can you find out what it is, in order to be certain that you don't exceed it?


There is no limit that I know of besides the memory limits of your graphics hardware, your system memory, your stack, your heap and the AGP bandwidth.

Now that think about it, the only times I have gotten OutOfMemory exceptions in C# are from infinite loops. It may be that the exception has nothing to do with this and comes from somewhere else in your code.

It is also hard to tell what is acutally going on in the unmanaged memory used by many directx objects. Calling Dispose is supposed to release the unmanaged resources right away, but memory management is a complicated thing and it may not work exactly or as quickly as you expect.

If you are really interested figuring this out try running the same code with the Reference device. You might also consider profiling it (check out PIX) to try to track down where the error is actually comming from.

You said it usualy fails wiht an OutOfMemory -- if it sometimes fails with an AccessViolation that could mean that some of your unmanaged objects are getting destroyed too early.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!