When i run my DirectX managed Game in SharpDevelop i get the following error message:
Error initalizing graphics: Error in the Application
The Debuger Produces This:
Exception System.ObjectDisposedException was thrown in debuggee:
Cannot access a disposed object.
CreateHandle()
CreateHandle()
get_Handle()
SetVisibleCore()
SetVisibleCore()
Show()
Main() - c:\projects\csharp\Space Xscape\Main.cs:17,4
Here is the code i'm using:
using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace SpaceXscape {
public class GameWindow : Form {
Device device = null;
//Think of this as your graphics card
static void Main() {
GameWindow gw = new GameWindow();
gw.InitializeGraphics();
gw.Show();
while(gw.Created) {
gw.Render();
//Where we tell our 'device' what to do
Application.DoEvents();
//let the OS handle what it needs to
}
}
private void InitializeGraphics() {
try {
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, presentParams);
}
catch (DirectXException e) {
MessageBox.Show(null, "Error initalizing graphics: " + e.Message, "Error");
Close();
}
}
private void Render() {
if(device == null) return;
device.Clear(ClearFlags.Target, System.Drawing.Color.Black, 1.0f, 0);
device.Present();
}
}
}
This is from this tutorial. Many people seem to have the same problem based on the comments. Any ideas?
Thanks,
Space Xscape