Nick Gravelyn

I'm going through my code to make sure everything properly releases and reloads when the device is destroyed, and I'm finding a problem with one particular case. I have a class that is basically a container for my bullets (textured quads). When the program runs initially everything runs fine, but if I minimize the window and bring it back up, all my models and things reload properly (including a textured model, non-textured model, and grid) except my bullet manager. Is there something tricky about something with the texture I figure the basic effect isn't my problem because my grid uses a basic effect. Here's the content loading code for it:

public override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
verts = new VertexPositionTexture[4];

verts[0] = new VertexPositionTexture(
new Vector3(-.2f, 0f, .4f),
new Vector2(0f, 0f)
);

verts[1] = new VertexPositionTexture(
new Vector3(.2f, 0f, .4f),
new Vector2(1f, 0f)
);

verts[2] = new VertexPositionTexture(
new Vector3(-.2f, 0f, -.4f),
new Vector2(0f, 1f)
);

verts[3] = new VertexPositionTexture(
new Vector3(.2f, 0f, -.4f),
new Vector2(1f, 1f)
);

vb = new VertexBuffer(
GraphicsDeviceService.GraphicsDevice,
VertexPositionTexture.SizeInBytes * 4,
ResourceUsage.None,
ResourceManagementMode.Automatic
);

vb.SetData<VertexPositionTexture>(verts);

vd = new VertexDeclaration(
GraphicsDeviceService.GraphicsDevice,
VertexPositionTexture.VertexElements
);

texture = content.Load<Texture2D>(textureName);

effect = new BasicEffect(GraphicsDeviceService.GraphicsDevice, null);
effect.Texture = texture;
effect.TextureEnabled = true;
}

base.LoadGraphicsContent(loadAllContent);
}

Edit:
Similarly, when the device is recreated, one of my models loads with reversed normals (well, technically they are wrong the first time they are loaded so when it is reloaded it looks right). I'm not sure why this is.


Re: XNA Framework Loading Content After Device Reset

Nick Gravelyn

So my problem I've determined that the content being loaded with opposite windings for vertices (or opposite normals, though I believe the two are the same). I'm not sure how this is happening, but it seems to depend on the content being loaded.

Currently I have four graphical objects being loaded and drawn. I have a simple generated grid that is created properly every time. My bullets (which used to flip when the device was recreated) are now correct no matter what. I have a textured model (.fbx file) loaded in that is correct both times (though it is simply a plane). My problem is my other model. It is also an .fbx file (non-textured), but when loaded the first time the normals appear reversed. When I minimize the window and pull it up again, the normals are reloaded correctly. Any ideas why




Re: XNA Framework Loading Content After Device Reset

Kyle_W

Certainly the normals shouldn't change based on reloading the model. Since you are not having problems with the other FBX models, perhaps the bullet model is corrupt or has non-manifold geometry in it. You might want to try re-creating it. You also said the bullets are being handled by a special class you created. Perhaps there is something odd that you are doing in that class. If the code for that class is not too big, perhaps you could post it. Are you performing any actions on the bullet model after loading it (other than setting its position, orientation, etc)



Re: XNA Framework Loading Content After Device Reset

Nick Gravelyn

The bullets are actually a simple quad with a texture that I produce in the game. I did fix the problem there (by changing the vertex order). I'll try recreating the model that is giving me problems and see if somehow it was merely exported incorrectly out of Maya.




Re: XNA Framework Loading Content After Device Reset

Nick Gravelyn

I exported a new version of the model and I still have the problem. I have figured out some other things though.

The normals are not reversed because switching to CullMode.None does not help at all. So it seems like it almost isn't loading the whole mesh until I reset the device. Again, I'm running the same loading code so I have no idea why that'd be.

Also I'm not actually reloading the model because during the device reset, loadAllContent is false so the model remains from the first load. Something about resetting the device is messing with my model though.

Another thing I've found is that it seems like my coordinate system is changing (and probably the culprit). My bullets are all drawn at 1 unit on the Y axis. When the game first loads, the model is drawn incorrectly and the bullets are drawn underneath the ground. Upon resetting the device, the model is drawn correctly and the bullets are drawn on above the ground.

This is quite a glitch and I'm figuring it's something I did, but I have no idea. Any ideas at all are welcome.