DX9 - Direct3D.Device - Error

Started by
11 comments, last by ISOPimp 21 years, 3 months ago
I am starting to write a DirectX program in C# by following the SDK tutorials. I know this might not be the best way to do this, but it should work none the less. I have started by Creating 2 classes. The first is CMain which just holds my main function:
  using System;
using System.Drawing;
using System.Windows.Forms;
using DX = Microsoft.DirectX;
using D3D = Microsoft.DirectX.Direct3D;

namespace Pong
{
   public class CMain
   {
      public CMain()
      {
      }
      [STAThread]
      static void Main()
      {
         CDevice app = new CDevice();
         if(!app.InitializeGraphics(true))
         {
            MessageBox.Show("Could Not Initialize Direct3D Device.\nExiting...");
            return;
         }
         app.ShowDialog();
      }
   }
}  
and the other one is the one to create the device, etc:
  using System;
using System.Drawing;
using System.Windows.Forms;
using DX = Microsoft.DirectX;
using D3D = Microsoft.DirectX.Direct3D;

namespace Pong
{
   public class CDevice : System.Windows.Forms.Form
   {
      private D3D.Device m_Device;
      private D3D.PresentParameters m_PP;

      public CDevice()
      {
         this.m_Device = null;
         this.m_PP = new D3D.PresentParameters();
         this.ClientSize = new System.Drawing.Size(800, 600);
         this.Name = "frmMain";
         this.Text = "Pong: DirectX Accelerated";
      }

      public bool InitializeGraphics(bool Fullscreen)
      {
         try
         {
            this.m_PP.Windowed = !Fullscreen;
            this.m_PP.SwapEffect = D3D.SwapEffect.Discard;
            this.m_PP.PresentationInterval = D3D.PresentInterval.Immediate;
            this.m_Device = new D3D.Device( 0, D3D.DeviceType.Hardware, this, D3D.CreateFlags.SoftwareVertexProcessing, this.m_PP);

            return true;
         }
         catch(DX.DirectXException e)
         {
            Console.WriteLine("\n+++++++++++\n{0}\nErrorCode: {1}\n+++++++++++", e.ToString(), e.ErrorCode);
            return false;
         }
      }
   }
}  
This is all the code my application uses, and I thought it should be able to create the device but if fails (throws an exception). I installed the debug runtimes and it tells me the error it throws is Unknown. I even put the error code in the error lookup utility, but again it came up with an error unknown. Here is what is printed by my Console.Writeline:
  +++++++++++
Error in the application.
-2146232832 (Unknown)
   at Microsoft.DirectX.Direct3D.Device..ctor(Int32 adapter, DeviceType deviceType, Control renderWindow, CreateFlags behaviorFlags, PresentParameters presentationParameters)
   at Pong.CDevice.InitializeGraphics(Boolean Fullscreen) in c:\documents and settings\micahh\my documents\visual studio projects\pong\cdevice.cs:line 31
ErrorCode: -2146232832
+++++++++++  
Could someone please tell me what is wrong, and why I can''t get a nice descriptive error from my debugger. Thanks in advance.
Advertisement
bump
Hi there! I think I solved your problem. I am however VERY new at C#.

Try add following to your pp:

this.m_PP.BackBufferWidth = 800;this.m_PP.BackBufferHeight = 600;this.m_PP.BackBufferFormat = D3D.Format.A8R8G8B8; 

_________________________ www.leXor.net
Thanks for the response, but this does not work for me. I tried other BackBuffer Formats as well, with no success. What would really help me is if I could get proper debugging messages, so if anyone knows how I can fix this, please let me know.
Can you dump the error code into DXTrace? They should''ve included a managed version of it for the C# libraries..

At least it''ll spit back a human readable message..

hth,
Learn about game programming!Games Programming in C++: Start to Finish
I searched all the DirectX Namespaces and I was unable to find a DXTrace (or Trace) for managed Code. I just checked dxdiag and it reports that d3d8.dll and d3d9.dll are Final Retail (along with some others) but I just installed the Debug runtimes and it continues to show these files as Final Retail. Just wondering if anyone else is having these problems and would care to help.
<Reverse Psychology>Hmmmmm... I guess I should go to a forum where people actually have some answers...</Reverse Psychology>

[edited by - ISOPimp on January 2, 2003 1:11:49 PM]
for most cards the only acceptable 32bit backbuffer is:
D3D.Format.X8R8G8B8
Well, I finally got Fullscreen to work using a BackBufferFormat of D3D.Format.R5G6B5 (using the caps viewer to get this Format). I still can''t get windowed mode to work but I think it is because I can only render to a R5G6B5 format for some reason, and my current display is something other than that.

I would still like a response as to why my debugger doesn''t tell me this information (It did in DX8.1 using c++).

Thanks for your help.
You won''t get a different format unless you card supports multiple backbuffer formats in windows.

If you can''t get X8R8G8B8 to work then I think you can try R8G8B8
if that works then I strongly suggest an upgrade because your hardware is way old.

This topic is closed to new replies.

Advertisement