Everything is fine till it gets to the ToString() Method. All the nodes are what they should be and everything. Any input on the 2nd one.
And again I say both of these can be reproduced by me by compiling the source code that comes with the book as well. Maybe it is a problem in the August SDK. Maybe some refrences are going null for some reason?
Ok here is the complete source for the first Null Reference problem.
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using Microsoft.DirectX;using Microsoft.DirectX.Direct3D;namespace Enumeration{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } public void LoadGraphics() { foreach (AdapterInformation ai in Manager.Adapters) { TreeNode root = new TreeNode(ai.Information.Description); TreeNode driverInfo = new TreeNode(string.Format("Driver information: {0} - {1}", ai.Information.DriverName, ai.Information.DriverVersion)); root.Nodes.Add(driverInfo); TreeNode displayMode = new TreeNode(string.Format("Current Display Mode: {0}x{1}x{2}", ai.CurrentDisplayMode.Width, ai.CurrentDisplayMode.Height, ai.CurrentDisplayMode.Format)); foreach (DisplayMode dm in ai.SupportedDisplayModes) { TreeNode supportedNode = new TreeNode(string.Format("Supported: {0}x{1}x{2}", dm.Width, dm.Height, dm.Format)); displayMode.Nodes.Add(supportedNode); } root.Nodes.Add(displayMode); treeView1.Nodes.Add(root); } } private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { if (e.Node.Parent == null) { textBox1.Text = e.Node.Text + " Capabilities: \r\n\r\n" + Manager.GetDeviceCaps (e.Node.Index, DeviceType.Hardware).ToString().Replace("\n", "\r\n"); // CAUSES THE NULL REF ERROR } } }}
Here is the complete source for the seccond Null Reference problem.
using System;using System.Collections.Generic;using System.Drawing;using System.Windows.Forms;using Microsoft.DirectX;using Microsoft.DirectX.Direct3D;namespace MDXApp{ public partial class Form1 : Form { private Device device = null; private VertexBuffer vb = null; private float angle = 0.0f; public Form1() { InitializeComponent(); this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); } /// <summary> /// We will initialize our graphics device here /// </summary> public void InitializeGraphics() { // Set out presentation parameters PresentParameters presentParams = new PresentParameters(); presentParams.Windowed = true; presentParams.SwapEffect = SwapEffect.Discard; // Create our device device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams); vb.Created += new EventHandler(this.OnVertexBufferCreate); // CAUSES NULL REF ERROR OnVertexBufferCreate(vb, null); } private void Form1_Paint(object sender, PaintEventArgs e) { device.Clear(ClearFlags.Target, Color.CornflowerBlue, 1.0f, 0); SetupCamera(); device.Lights[0].Type = LightType.Point; device.Lights[0].Position = new Vector3(); device.Lights[0].Diffuse = Color.White; device.Lights[0].Attenuation0 = 0.2f; device.Lights[0].Range = 10000.0f; device.Lights[0].Update(); device.Lights[0].Enabled = true; device.BeginScene(); device.VertexFormat = CustomVertex.PositionNormalColored.Format; device.SetStreamSource(0, vb, 0); device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1); device.EndScene(); device.Present(); this.Invalidate(); } private void SetupCamera() { device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, this.Width / this.Height, 1.0f, 100.0f); device.Transform.View = Matrix.LookAtLH(new Vector3(0, 0, 5.0f), new Vector3(), new Vector3(0, 1, 0)); device.RenderState.Lighting = true; device.RenderState.CullMode = Cull.None; device.Transform.World = Matrix.RotationAxis(new Vector3(angle / ((float)Math.PI * 2.0f), angle / ((float)Math.PI * 4.0f), angle / ((float)Math.PI * 6.0f)), angle / (float)Math.PI); angle += 0.1f; } private void OnVertexBufferCreate(object sender, EventArgs e) { VertexBuffer buffer = (VertexBuffer)sender; CustomVertex.PositionNormalColored[] verts = new CustomVertex.PositionNormalColored[3]; verts[0].Position = new Vector3(0.0f, 1.0f, 1.0f); verts[0].Normal = new Vector3(0.0f, 0.0f, -1.0f); verts[0].Color = Color.Aqua.ToArgb(); verts[1].Position = new Vector3(-1.0f, -1.0f, 1.0f); verts[1].Normal = new Vector3(0.0f, 0.0f, -1.0f); verts[1].Color = Color.Black.ToArgb(); verts[2].Position = new Vector3(1.0f, -1.0f, 1.0f); verts[2].Normal = new Vector3(0.0f, 0.0f, -1.0f); verts[2].Color = Color.Purple.ToArgb(); buffer.SetData(verts, 0, LockFlags.None); } }}
[Edited by - TheNobleOne on August 20, 2005 9:00:47 AM]