Archived

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

ISOPimp

DX9 - Direct3D.Device - Error

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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;


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Always check the results of the functions that are failing. DX9 has a nice little program which you enter the hex error number and it will then tell you what failed in the function. Granted it''s often not very specific but it will give you a place to look and usually you can figure it out with out any help.

Share this post


Link to post
Share on other sites
Thanks to everyone that has replied. I have resolved the problem (My card only supports 16-bit color for 3D) but am still troubled by the fact that the debugger did not give me a "BackBuffer Format invalid" or similar message. I remember getting a message like this a while ago using DX8.1 and C++.

quote:
Always check the results of the functions that are failing....
I do check most of the functions for proper results, unfortunatly in this case the program fails during construction rather than a function call so an exception is thrown. It seems that either the Exception handling in DX9 is incomplete or my debug runtimes are not installed properly.

quote:
... run the "DirectX Caps Viewer" tool ...
Damn, if you would have suggested that when I first posted I would have resolved this along time ago. As stated above, this was how I eventually did solve this problem.

Share this post


Link to post
Share on other sites