Sign in to follow this  
Riviera Kid

Simplifying meshes, Managed Dx C# help

Recommended Posts

Hi, i am working my way through Managed Direct x 9 kickstart by tom miller and there are some differences in the code. I can correct most of them myself but i am having a problem simplifying meshes. i am using the latest direct x and .net pg 125. this is what i have atm.
private void LoadMesh(string file)
{
     ExtendedMaterial[] mtrl;
     GraphicsStream adj;

     // Load our mesh
     mesh = Mesh.FromFile(file, MeshFlags.Managed, device,out adj, out mtrl);

     // If we have any materials, store them
     if ((mtrl != null) && (mtrl.Length > 0))
     {
          meshMaterials = new Material[mtrl.Length];
          meshTextures = new Texture[mtrl.Length];

          // Store each material and texture
          for (int i = 0; i < mtrl.Length; i++)
          {
               meshMaterials[i] = mtrl[i].Material3D;
               if ((mtrl[i].TextureFilename != null) && (mtrl[i].TextureFilename != string.Empty))
               {
                    // We have a texture, try to load it
                    meshTextures[i] = TextureLoader.FromFile(device, @"..\..\" + mtrl[i].TextureFilename);
                }
           }
      }
	//clean our main mesh
	Mesh tempMesh = Mesh.Clean(CleanType.Simplification,mesh,adj,adj);
			
	//replace our existing mesh with this one
	mesh.Dispose();
	mesh = tempMesh;

	//get our simplified mesh
			
	simplifiedMesh = Mesh.Simplify(mesh,adj,null,1,MeshFlags.SimplifyVertex);		
}

it gives me an exception. An unhandled exception of type 'System.NullReferenceException' occurred in microsoft.directx.direct3dx.dll Additional information: Object reference not set to an instance of an object. the problem is in trying to simplify and not the loading, the last method throws the exception. any help would be much appreciated. Thank you Riviera Kid [Edited by - Riviera Kid on November 25, 2004 8:27:01 AM]

Share this post


Link to post
Share on other sites
Not entirely sure on this one, but I believe that on this line:

Mesh tempMesh = Mesh.Clean(CleanType.Simplification,mesh,adj,adj);

if the cleaning fails, it returns the same mesh, and probably the "adjacencyOut" which is your adj graphicsstream get filled with a null value, cause the cleaning failed.

that's just my guess by looking at the directx docs

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
This is thread starter, rivierakid

in the text book the overload is

Mesh.Clean(mesh,adj,adj);

but it seams the last updates have changed the overload
so i wasnt really sure what to do instead.

why would the clean fail?

Share this post


Link to post
Share on other sites
Don't dispose the mesh...just assign the mesh like :

mesh = tempMesh;

There seems to be a problem with the disposing of the original mesh also disposing the tempMesh (although they are not the same reference).

It's not really a memory leak since the GC will eventually get to it.

Shadx

Look at : http://www.gamedev.net/community/forums/topic.asp?topic_id=285414

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