Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Release build fails, debug does not?

Started by mekrob Jul 4, 2007 at 2:32 PM 3 replies 650+ views
Original Post
mekrob
mekrob
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
 
protected override void OnPaint(PaintEventArgs e)
        {
            
            _deltaTime = HiResTimer.GetElapsedTime();
            
            CheckForInput();
            
            Render();

            this.Invalidate();
             
        }

My CheckForInput() Method


 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;
        
        }


And finally my Render method


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();
        }


mekrob
mekrob
It would be great if the exception info contained the line number, but it doesn't appear to :(

I am new to c#, I am trying to pick it up as I learn directX (I know mostly VB / c++). How can I debug a release build with visual studio? If I start the debugger the program works fine.
mekrob
mekrob
Something odd just happened. I set the "Define DEBUG constant" flag and rebuilt my program, and I got NO unhandled exception! It works now!

Any ideas what happened? Thanks for the help :)
darookie
darookie
You introduced a nasty hack to hide the actual problem rather than solving it [smile]. You should really try and set a breakpoint into the offending method. Breakpoints work in release mode, too (in, .NET that is). It looks as if one of your referenced object isn't initialised for some reason. To find out which object exactly, you really should try and either a) use the debugger (works in release mode) or b) use logging to narrow down the location.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.