XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

Graphics Initalization Error: Error In Application

Last post 02-01-2008 5:58 AM by Bad Habit. 2 replies.
  • 12-13-2007 10:02 AM

    Graphics Initalization Error: Error In Application

    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

  • 01-31-2008 9:36 PM In reply to

    Re: Graphics Initalization Error: Error In Application

    You might want to put that inside a Code Snippet (that little button at the bottom-right of the toolbar) before posting. Because I'm not reading that.

    Either way, from what I can tell, an exception was generated somewhere in the method "InitializeGraphics()" (and if you notice, the error message matches the text that says "Error initializing graphics: "). So something went wrong there along the line. Now, I'm not exactly firmiliar with that API anymore, or what SharpDevelop even is. I'm not even sure what "GameWindow" is doing there; the tutorial seems to be just using forms.

    The only thing I can think of is that your graphics card might not support DX9, but it seems to be complaining about trying to use a disposed object. So, you probably messed up somewhere along the line.

    Now, I'm tired, and I'm having some trouble trying to understand your problem. Could you at least show us what line generated that problem?

    Ehh.. you're a programmer, you can solve your own problems, can't you? We're not gonan dig-down in to your code and find the problem for you. You seem capable of solving this on your own.

  • 02-01-2008 5:58 AM In reply to

    Re: Graphics Initalization Error: Error In Application

    You want to show the window first then initialise the graphics.
Page 1 of 1 (3 items) Previous Next