Jump to content
  • Advertisement

Archived

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

ISOPimp

DX9 - Direct3D.Device - Error

This topic is 5742 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
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,

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
<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]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
for most cards the only acceptable 32bit backbuffer is:
D3D.Format.X8R8G8B8

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!