• ### Announcements

#### Archived

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

# 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()
{
}
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.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.

bump

##### Share on other sites
Hi there! I think I solved your problem. I am however VERY new at C#.

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

##### 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 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 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 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 on other sites
for most cards the only acceptable 32bit backbuffer is:
D3D.Format.X8R8G8B8

##### 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++).

##### Share on other sites
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 on other sites
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 on other sites
hm.. run the "DirectX Caps Viewer" tool which can be found in the start menu, under
Microsoft DirectX 9.0 SDK > DirectX Utilities
there you''ll see which backbuffer formats are supported by your graphics hardware

##### 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.

• ### Forum Statistics

• Total Topics
628282
• Total Posts
2981805

• 9
• 10
• 11
• 17
• 14