Debug = fine, Release = crash[SOLVED]

Started by
22 comments, last by Promit 15 years, 9 months ago
I've gone through the whole project three times now and I saw zero variables that were not initialized. I really have no idea what it could be. Is there a way to debug the release? I know a .pdb file was generated for the release build...so I assume its possible.
Advertisement
If I run my release build in debug mode, at least VC shows where the error happened. The only other suggestion I can give is progressively removing parts of your code until that error disappears, and starting from there to spot the wrong instructions....
Seems like a "shrödingers bug", a bug which does not happen when observed :).

Typical difference between debug and release is the handling of uninitialized variables and initialized memory. When memory is allocated/freed in debug mode it is usually filled with a special pattern. The same goes for uninitialized variables. You need to make absolutely sure you haven't got any uninitialized variables/dangling pointer references/uninitialized memory usage.

The directx drivers can have slightly different behavior depending on debug/release mode. So you could try using debug drivers in release mode and vice versa. The same goes for other libraries which have both debug and release mode.

Make sure you never return references to local variables, optimizations can change how the stack is used and cause different behavior in release and debug.
Quote:Original post by mzeo77
Seems like a "shrödingers bug", a bug which does not happen when observed :).


Or better yet, there is a bug and there is't a bug, at the same time, until you run the program: then there is 50% of probabilities that the program will crash, and 50% of probabilities that it wont :-)
I always use to say, when situation like OP problem, that all those who say that computer are deterministic device don't know what they are talking about :-)
Ok...I think I'm going to try the comment out all of my code until I narrow it down. I can't run the release build in debug mode because vc# doesn't let me unfortunately. Unless there is a way that I don't know about.
Are you reading/writing from any files? The working directory of the executable changes between release and debug.

Also what language/API are you using? You keep referring to C#, but then talk about directX libs like you're futzing about with unmanaged dlls.
Quote:Original post by Telastyn
Are you reading/writing from any files? The working directory of the executable changes between release and debug.

Also what language/API are you using? You keep referring to C#, but then talk about directX libs like you're futzing about with unmanaged dlls.


I didn't noticed it before, but now I wonder which language are you using: what I wrote before was based on the idea that you were using c++, and c# should crash with a pretty detailed exception message...
I'm using SlimDX for the DirectX API.

I found the problem anyway. I have my GameManager class, which is the central point for the game. In the constructor I have this line of code to basically run the game loop.

Application.Idle += new EventHandler(Application_Idle);

This is the line that is making it die, and I'm not quite sure why. Either release doesn't like me setting that event handler for some weird reason, or the way I run the application idle loop is what it doesn't like.

        /// <summary>        /// This is our game loop.        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        void Application_Idle(object sender, EventArgs e)        {            while (NativeMethods.AppStillIdle)            {                Application.DoEvents();                if (_renderer.IsDeviceLost)                {                    _logger.Write("Device lost");                    Thread.Sleep(50);                    Result result = _renderer.Device.TestCooperativeLevel();                    if (result.IsFailure)                    {                        if (result == SlimDX.Direct3D9.ResultCode.DeviceLost)                            continue;                    }                    if (_renderer.ResetDevice().IsFailure)                    {                        _logger.Write("Failed to reset the device");                        continue;                    }                }                _renderer.IsDeviceLost = false;                GameFrame();            }        }


    public static class NativeMethods    {        [DllImport("User32.dll", CharSet = CharSet.Auto)]        [return: MarshalAs(UnmanagedType.Bool)]        static extern bool PeekMessage(out Message msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);        public static bool AppStillIdle        {            get            {                Message msg;                return !PeekMessage(out msg, IntPtr.Zero, 0, 0, 0);            }        }    }
I'd look right into Application.DoEvents. IIRC, this is a convenience method for event handling that might be extraneous since you're doing the peeking yourself.
Quote:Original post by Telastyn
I'd look right into Application.DoEvents. IIRC, this is a convenience method for event handling that might be extraneous since you're doing the peeking yourself.


K, I took that out and it still crashed. I commented out a lot of the stuff in the Application_Idle method, but the only thing that makes it stop crashing is the new EventHandler line.

This topic is closed to new replies.

Advertisement