Skip to main content
GameDev.net gamedev.net
🔒 Locked

DirectX C#

Started by Ksingh30 Sep 15, 2006 at 4:56 PM 0 replies 1.8k views
Original Post
Ksingh30
Ksingh30
please help me I been getting this error for weeks, cant find out how to fix this.

CustomVertex.TransformedColored[] vertices=new CustomVertex.TransformedColored[3];
 
             vertices[0].Position = new Vector4(150f, 100f, 0f, 1f);
             vertices[0].Color = Color.Red.ToArgb();
             vertices[1].Position = new Vector4(this.Width/2+100f, 100f, 0f, 1f);
             vertices[1].Color = Color.Green.ToArgb();
             vertices[2].Position = new Vector4(250f, 300f, 0f, 1f);
             vertices[2].Color = Color.Yellow.ToArgb();

            device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);

            device.BeginScene();
                Player1.Draw();
                           device.VertexFormat = CustomVertex.TransformedColored.Format;
             device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices);
           
            device.EndScene();
           device.Present();
and I get this error when the code gets to this line. device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices); this is the error I get. An unhandled exception of type 'Microsoft.DirectX.Direct3D.InvalidCallException' occurred in Microsoft.DirectX.Direct3D.dll Additional information: Error in the application.
vermilion_wizard
vermilion_wizard
I've had that kind of problem in the past.. it's a real pain, because probably it's somewhere else in your code that's the problem. Try commenting out Player1.Draw for starters.

I wrote this real quick, using your source code, and it works on my machine. Try starting up a new project, add Microsoft.DirectX and Microsoft.DirectX.Direct3D references and replace the form code with this to see if it works. Then you can take it and slowly make it look like your code in your other project. If you do it one line at a time and test it between each line, you should be able to narrow down the problem quickly.

   public partial class Form1 : Form    {        Device device;        public Form1()        {            InitializeComponent();        }        private void Form1_Load(object sender, EventArgs e)        {            PresentParameters p = new PresentParameters();            p.DeviceWindow = this;            p.EnableAutoDepthStencil =false;            p.BackBufferHeight = this.Height ;            p.BackBufferWidth = this.Width ;            p.BackBufferCount = 1;            p.BackBufferFormat = Format.Unknown;            p.Windowed = true;            p.PresentationInterval = PresentInterval.Immediate;            p.PresentFlag = PresentFlag.LockableBackBuffer;            p.SwapEffect = SwapEffect.Copy;            device = new Device(Manager.Adapters.Default.Adapter, DeviceType.Hardware,                 this.Handle, CreateFlags.SoftwareVertexProcessing,               p );        }        private void Form1_Paint(object sender, PaintEventArgs e)        {            CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[3];            vertices[0].Position = new Vector4(150f, 100f, 0f, 1f);            vertices[0].Color = Color.Red.ToArgb();            vertices[1].Position = new Vector4(this.Width / 2 + 100f, 100f, 0f, 1f);            vertices[1].Color = Color.Green.ToArgb();            vertices[2].Position = new Vector4(250f, 300f, 0f, 1f);            vertices[2].Color = Color.Yellow.ToArgb();            device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);            device.BeginScene();            //Player1.Draw();            device.VertexFormat = CustomVertex.TransformedColored.Format;            device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices);            device.EndScene();            device.Present();        }    }

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.