Sign in to follow this  
CC Ricers

XNA: Meshes rendering improperly after changing display modes

Recommended Posts

While I was testing out functions to resize the window or toggle full screen, I found a big problem. The meshes in my scene that have existed before changing display modes or resolution either disappear, or render with the vertices/indices incorrectly, so a lot of triangles are out of place. I set all my index buffers/vertex buffers in the game's Draw function. I know it has to do with the graphics device being reset, but how do you restore these buffers properly in XNA? Do I need to construct new ones?

 

I have looked online on how to re-load resources in XNA when the graphics device is lost or reset, but they just tend to focus on Render Targets. I haven't seen anything about meshes being drawn with vertices out of order. I'll provide a screenshot of the problem later when I'm on my home computer.

 

(Edit) I have also tried to debug the situation using PIX. The program crashes when I click on the Mesh tab for a DrawPrimitive call.

Edited by CC Ricers

Share this post


Link to post
Share on other sites

If you're just using VertexBuffer, XNA (or DirectX?) should handle recreating the resources automatically.

 

If you're using a DynamicVertexBuffer, you're responsible for resetting the data on your own. DynamicVertexBuffer has a ContentLost event handler you use to know when it's needed. I think you just need to SetData again.

Share this post


Link to post
Share on other sites

If you're just using VertexBuffer, XNA (or DirectX?) should handle recreating the resources automatically.

 

If you're using a DynamicVertexBuffer, you're responsible for resetting the data on your own. DynamicVertexBuffer has a ContentLost event handler you use to know when it's needed. I think you just need to SetData again.

 

Ah, that could be it then. I'm using Dynamic VB's and IB's mostly for the chunks of the terrain that need to be re-built (I create a new VB and set the data every time it needs to be updated with new information from the world).

 

I'm gonna first try switching to regular VB's and see if that fixes the problem, and if performance is still good. If not I will try what you suggest. Looks like I have to hook a function with the even, to reset the data from the chunk.

Edited by CC Ricers

Share this post


Link to post
Share on other sites

I changed the dynamic vertex and index buffers to regular ones and that solved the problem. I thought I would have needed dynamic buffers but I don't see a change in performance just with the regular buffers.

Share this post


Link to post
Share on other sites

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