C# + DIrect3D
От: SPP  
Дата: 13.01.06 07:58
Оценка:
public struct MeshInfo
{
private Mesh mesh;
private Material[] meshMaterials;
private Texture[] meshTextures;
public Mesh Model { get { return mesh; } set { mesh = value; } }
public Material[] Materials { get { return meshMaterials; } set { meshMaterials = value; } }
public Texture[] Textures { get { return meshTextures; } set { meshTextures = value; } }
}

public class MainClass : System.Windows.Forms.Form
{
public MeshInfo[] meshes = null;
public int meshIndex = 0;
/* ... */
private void AddPredmet()
{

ExtendedMaterial[] mtrl = null;

// Загрузка меша
/* на этой строчке выдает Exception */
meshes[meshIndex].Model = Mesh.FromFile(path, MeshFlags.Managed, device, out mtrl);

// Сохраняем материалы, если они есть
if ((mtrl != null) && (mtrl.Length > 0))
{
meshes[meshIndex].Materials = new Material[mtrl.Length];
meshes[meshIndex].Textures = new Texture[mtrl.Length];

// Сохраняем текстуры, если есть
for (int i = 0; i < mtrl.Length; i++)
{
meshes[meshIndex].Materials[i] = mtrl[i].Material3D;
if ((mtrl[i].TextureFilename != null) && (mtrl[i].TextureFilename != string.Empty))
{
meshes[meshIndex].Textures[i] = TextureLoader.FromFile(device, @"..\..\" + mtrl[i].TextureFilename);
}
}
}
}
}


При выхове функции AddPredmet() выдается exception:

An unhandled exception of type 'System.NullReferenceException' occurred in Project.exe
Additional information: Object reference not set to an instance of an object.

Как я понимаю, это потому, что не инициализирована переменная meshes. Только как это сделать? Или может в чем другом дело?
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.