Archived

This topic is now archived and is closed to further replies.

whats wrong with this code...

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

Hi, Whats wrong with this c# code? I get an object reference not set to an instance of an object in line 10 of the following piece of code: if(line.StartsWith("nummeshes ")) { numMeshes = Int32.Parse(line.Substring(line.LastIndexOf(" "))); meshes = new Mesh[numMeshes]; } for(int m=0; m[edited by - xyz on March 18, 2004 3:46:46 PM]

Share this post


Link to post
Share on other sites
reposted for readibility (use [ source ] //code goes here [ /source ] without the spaces to post code)


if(line.StartsWith("nummeshes "))
{
numMeshes = Int32.Parse(line.Substring(line.LastIndexOf(" ")));
meshes = new Mesh[numMeshes];
}

for(int m=0; m<numMeshes; m++)
{
if(line.StartsWith("numfaces "))
{
meshes[m].numFaces = Int32.Parse(line.Substring(line.LastIndexOf(" ")));
meshes[m].faces = new Face[meshes[m].numFaces];
}
}

Share this post


Link to post
Share on other sites
are you sure that you are actually entering the block of code beginning with:
if(line.StartsWith("nummeshes "))

if you aren''t then you won''t have created the meshes array. as a first stab, change the first part of the code to this:


if(line.StartsWith("nummeshes "))
{
numMeshes = Int32.Parse(line.Substring(line.LastIndexOf(" ")));
meshes = new Mesh[numMeshes];
}
else
{
//print out an error message saying something like

//"couldn''t create meshes array

numMeshes = 0;
}

Share this post


Link to post
Share on other sites