C# .NET - Problems creating a managed Direct X device (C#)

Asked By Henrk Nielsen
05-Oct-04 04:03 PM
Hi

I'm having a problem creating a basic Direct X device, from a tutorial.
The code does nothing fancy - it creates a device, but it doesn't render anything. Its very basic. It compiles, no problem, but I get a runtime error that occurs when creating the device:

device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);

The debugger says the following:

An unhandled exception of type 'Microsoft.DirectX.Direct3D.InvalidCallException' occurred in microsoft.directx.direct3d.dll
Additional information: Error in the application.

I've been updating everything (DirectX SDK, DirectX runtime, .NET servicepack) but nothing fixes the problem.

My graphics card is a GeForce 2 from 2001. I don't know if this matters...?

I really hope someone has an idea of what causes this runtime error.

/Henrik
  Asked By david duguay
08-Oct-04 11:58 AM
I have built a 3d engine in c# without any problems, I don't see nothing wrong with your code. Can you show me how you have defined your "presentParams". The bug could be in there.

here is my init code for my engine:
PresentParameters parametres = new PresentParameters();
parametres.Windowed=true;
parametres.SwapEffect = SwapEffect.Discard;
parametres.AutoDepthStencilFormat = DepthFormat.D16;
parametres.EnableAutoDepthStencil = true;
device = new Device(0,DeviceType.Hardware,handle,CreateFlags.HardwareVertexProcessing,parametres);

notice that I used HardwareVertexProcessing. Its much faster than software since it use the hardware to procces the vertex. the handle is a pointer on a form

David
  Asked By Henrk Nielsen
08-Oct-04 02:32 PM
Hi - thanks for your reply.

Here is the code:

public void InitializeGraphics()
{
	PresentParameters presentParams = new PresentParameters();

	presentParams.Windowed = true;
	presentParams.SwapEffect = SwapEffect.Discard;

	device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
}


Yes - I guess HardwareVertexProcessing is faster, but the tutorial I follow, advice me to go for the SoftwareVertexProcessing to start with, as this should be the "safer" choice with an older graphics card (like mine) which might not support some features.

I've tried changing to HardwareVertexProcessing but the runtime error still occures...

/Henrik

hmm   Maybe its the handle  hmm Maybe its the handle

12-Oct-04 11:20 AM
Where is this methode, in your form class on in a independent class? 

The device = new device need to have a form handle to work on. In my case, I send a pointer from a pictureBox:

init (System.Windows.Forms.PictureBox handle)
{
...
...
device = new Device(0,DeviceType.Hardware,handle,CreateFlags.HardwareVertexProcessing,parametres);
...
...
}

in the form class, i call it like this:

init (this.myPictureBox);

of course, if you use a form insted, use a init (System.Windows.Forms.Form handle)

adn call it like this: 
init (this);
From the form class.

David Duguay
Create New Account
help
How can we know a state of a thread? (A) What is use of Interlocked class ? (A) What is a monitor object? (A) What are wait handles? (A) What is ManualResetEvent and Webservices (B)What is an application domain? (B) What is .NET Remoting? (B) Which class does the remote object has to inherit? (I) what are two different types of remote Cache substitution? Chapter 6: OOPS (B) What is Object Oriented Programming? (B) What is a Class? (B) What is an Object? (A) What is the relation between Classes and Objects? (B Overriding? (I) what is the difference between delegate and events? (B) If we inherit a class do the private variables also get inherited? (B) What is the different accessibility levels defined in .NET? (I) Can you prevent a class from overriding? (I) what is the use of “Must inherit” keyword in VB.NET? (I Do interface have accessibility modifier. (A) What are similarities between Class and structure? (A) What is the difference between Class and structure’s? (B) What does virtual keyword mean? (B) What are shared (VB.NET to disable client side script in validators? (A)How can I show the entire validation error message in a message box on the client side? (B)You find that one of
cannot be used with indexers, destructors, or types. In C#, the static keyword indicates a class variable. In VB, the equivalent keyword is Shared. Its scoped to the class in which it occurs. Example a. Static int var / / in c#.net b. static void first version of .NET released? • Ans : The final version of the 1.0 SDK and runtime was made publicly available around 6pm PST on 15-Jan-2002. At the same time available to MSDN subscribers. • 03. What platforms does the .NET Framework run on? • Ans : The runtime supports Windows XP, Windows 2000, NT4 SP6a and Windows ME / 98. Windows 95 is not implement the .NET framework on Linux. • 04. What is the CLR? • Ans : CLR = Common Language Runtime. The CLR is a set of standard resources that (in theory) any .NET program can the following CLR resources in his MSDN PDC# article:Object-oriented programming model (inheritance, polymorphism, exception handling, garbage collection) Security model Type system All .NET base classes Many .NET framework classes CTS? • Ans : CTS = Common Type System. This is the range of types that the .NET runtime understands, and therefore that .NET applications can use. However note that not all .NET languages theory this allows very tight interop between different .NET languages - for example allowing a C# class to inherit from a VB class. • 07. What is IL? • Ans : IL = Intermediate Language. Also
what is exception handling and what is use of exception handling end of post Exception Handling: "EXCEPTION IS A RUNTIME ERROR WHICH ARISES BECAUSE OF ABNORMAL CONDITION INA CODE SEQUENCE. " In C# Exception is a class in the system namespace. An object of an exception is that describe the exceptional conditions
Interface and Abstract Class Hai, When do we go for Interface. . When do we go for Abstract Class. . .Give one example Today i faced one interview . . He asked this question.I want answer with Example Thanks in Advance Abstract Class :: - It cannot defines all the methods - It has subclass. - Here, Subclass is useless - A class can be extend an abstract class Interface :: - It defines all the methods - It must have implementations by other classes, But there http: / / kyapoocha.com / c-sharp-interview-questions / what%E2%80%99s-the-difference-between-an-interface-and-abstract-class-5 / http: / / www.dotnetuncle.com / Difference / 4_abstract_class_interface.aspx Hope this helps. HI An interface contains signatures of methods , delegates or events . The implementation of the methods is done in the class that implements the interface, as shown in the following example: interface ISampleInterface { void SampleMethod(); } class ImplementationClass : ISampleInterface { / / Explicit interface member implementation: void ISampleInterface.SampleMethod() { / / Method implementation. } static void Main() { / / Declare