System.NullReferenceException was unhandled RRS feed

  • Question

  • Recently, while browsing through the code4fun website, I found a tutorial for first timers to write 3d games in directx. The tutorial I am talking about is the one in which you learn to write a BattleTank game. I reached the second chapter, where Directx was introduced, where I got a problem.

    Now, I keep getting an exception:

    System.NullReferenceException was unhandled
      Message="Object reference not set to an instance of an object."
           at Microsoft.DirectX.Direct3D.Manager.get_AdapterCount()
           at Microsoft.DirectX.Direct3D.Manager.get_Adapters()
           at BattleTank2005.GameEngine..ctor() in C:\Documents and Settings\Aasim\My Documents\MSDN\Coding4Fun Sample- Intro to DirectX\C#\BattleTank2005\GameEngine.cs:line 30
           at BattleTank2005.Program.Main() in C:\Documents and Settings\Aasim\My Documents\MSDN\Coding4Fun Sample- Intro to DirectX\C#\BattleTank2005\Program.cs:line 19
           at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()


    at this line

    // Get the ordinal for the default adapter

    int adapterOrdinal = Manager.Adapters.Default.Adapter;

    I tried replacing the statement by

    int adapterOrdinal = 0; // for default device is 0

    but then i got the same exception in the next line:

    // Get our device capabilities so we can check them to set up the CreateFlags

    Caps caps = Manager.GetDeviceCaps(adapterOrdinal, DeviceType.Hardware);


    I use C# 2005 express edition and directx sdk april 2006 version. The tutorial where i learnt this code used directx february 2006 version and c# 2005. cud this be creating any problems?

    Saturday, November 25, 2006 2:02 AM