Original Post
Once again thank you all for taking the time to help me with my problem. I have come accross something I have never encountered before. My program works fine in debug builds but when I compile it to a release build .exe my program throws an unhandled exception and all I can see is a white window with two red outlines of triangles... ************** Exception Text ************** System.NullReferenceException: Object reference not set to an instance of an object. at ArcaneStorm.GameEngine.CheckForInput() at ArcaneStorm.GameEngine.OnPaint(PaintEventArgs e) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs) at System.Windows.Forms.Control.WmPaint(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ContainerControl.WndProc(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) I have found that if I comment out my calls to CheckForInput() and Render() in my OnPaint method, the error does not occur. Both CheckForInput() and Render() must be commented out or the error still happens. I have tried looking for uninitialized variables in these methods without any luck. If anyone spots anything out of place that may be causing the error I am seeing, please let me know! Thanks again. My OnPaint method My CheckForInput() Method And finally my Render method
protected override void OnPaint(PaintEventArgs e)
{
_deltaTime = HiResTimer.GetElapsedTime();
CheckForInput();
Render();
this.Invalidate();
}
private void CheckForInput()
{
// Check for user input
_keyboard.Poll();
_mouse.Poll();
if (_keyboard.State[Key.Escape])
{
Application.Exit();
}
// Move forward and back along the Z-axis
if (_keyboard.State[Key.W])
_camera.MoveForward(_moveSpeed * _deltaTime);
if (_keyboard.State[Key.S])
_camera.MoveForward(-_moveSpeed * _deltaTime);
// Move left and right along the X-axis
if (_keyboard.State[Key.A])
_camera.Strafe(-_moveSpeed * _deltaTime);
if (_keyboard.State[Key.D])
_camera.Strafe(_moveSpeed * _deltaTime);
if (_keyboard.State[Key.UpArrow])
_camera.AdjustPitch(-3f * _deltaTime);
if (_keyboard.State[Key.DownArrow])
_camera.AdjustPitch(3f * _deltaTime);
if (_keyboard.State[Key.RightArrow])
_camera.AdjustYaw(3f * _deltaTime);
if (_keyboard.State[Key.LeftArrow])
_camera.AdjustYaw(-3f * _deltaTime);
if ((_keyboard.State[Key.LeftShift]) && (_camera.Jumping == false))
{
_camera.Jump();
}
// Shoot a fireball if space is hit
if ((_keyboard.State[Key.Space]))
{
spritestruct newsprite = new spritestruct();
newsprite.position = _camera.Position;
newsprite.angles = _camera.Look;
spriteList.Add(newsprite);
}
// If you enable these keys you need to turn off the
// terrain height adjustment in the Render method
//_camera.SetHeight ( _terrain.TerrainHeight ( (int)_camera.Position.X, (int)_camera.Position.Z ) );
// Move up and down along the Y-axis
//if (_keyboard.State[Key.Q])
// _camera.UpDown(moveSpeed * _deltaTime);
//if (_keyboard.State[Key.Z])
// _camera.UpDown(-moveSpeed * _deltaTime);
if (_keyboard.State[Key.F1])
_fillMode = FillMode.WireFrame;
if (_keyboard.State[Key.F2])
_fillMode = FillMode.Solid;
if (_keyboard.State[Key.F3])
_fillMode = FillMode.Point;
if (_keyboard.State[Key.F4])
_lightOn = true;
if (_keyboard.State[Key.F5])
_lightOn = false;
}
private void Render()
{
// Force the Y to be the height of the terrain
// turn of input for Y
try
{
_camera.SetHeight(_terrain.TerrainHeight((int)_camera.Position.X, (int)_camera.Position.Z), _deltaTime);
}
catch
{
// Off the terrain grid
}
_camera.Update();
// Play with these settings
_device.RenderState.FillMode = _fillMode;
_device.Lights[0].Enabled = _lightOn;
/*
foreach (Tank tank in _tanks)
{
tank.Update(_deltaTime);
}
*/
// Clear the screen
_device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
// Tell DirectX we are about to draw something
_device.BeginScene();
_skyBox.Render(_camera);
_terrain.Render();
RenderUnits();
// Draw any fireball sprites
if (spriteList.Count > 0)
DrawSprites();
RenderFonts();
// Tell DirectX that we are done drawing
_device.EndScene();
// Flip the back buffer to the front
_device.Present();
}