Sign in to follow this  
Stormtrooper

Debug = fine, Release = crash[SOLVED]

Recommended Posts

Hello all, I'm wondering what would cause a crash in the release version of my program but not in the debug version? Its really weird when it crashes tho. DirectX 9 Debug runtimes report no errors or memory leaks, return errors with the release version, but no memory leaks. It usually crashes either after rendering one frame or right after it brings up the window which is when I initialize DirectX. The wierd part is before I create the window I write text to the logger, which is not getting written(I call flush after each write) to the text file. Any ideas on what it could be? See Last Post [Edited by - Eeyore on July 26, 2008 6:40:18 PM]

Share this post


Link to post
Share on other sites
Which compiler are you using?

You can try going into the compiler settings (Project properties in MSVC) and changing features such as Optimisation and run-time checking to be the same as debug (do one at a time) until you find a combination of settings that doesn't crash. This might give you a hint as to what is causing it.

Share this post


Link to post
Share on other sites
I remember that often when a debug works and a release doesn't the reason is an uninitialized variable or access to uninitialized memory: IIRC in debug memory is initialized to a default value, but in release memory and variable content is undefined until explicitly assigned, so this may cause the crash... Try to look at variable and memory access while debugging to see if you access a memory location with the defaul value (I don't remember wich is it though)...

Share this post


Link to post
Share on other sites
Quote:
Original post by Eeyore
DirectX 9 Debug runtimes report no errors or memory leaks, return errors with the release version, but no memory leaks.
D3D is giving you errors in release mode? What errors? I's make sure they're fixed first.

Share this post


Link to post
Share on other sites
Quote:
Original post by cignox1
I remember that often when a debug works and a release doesn't the reason is an uninitialized variable or access to uninitialized memory: IIRC in debug memory is initialized to a default value, but in release memory and variable content is undefined until explicitly assigned, so this may cause the crash... Try to look at variable and memory access while debugging to see if you access a memory location with the defaul value (I don't remember wich is it though)...

Exactly what I was thinking.

I would step through and make sure that everything is getting initialized as expected. I have had similar things happen in the past and it has always turned out that I have made a silly mistake somewhere.

Share this post


Link to post
Share on other sites
In debug generally variables are spaced out in order to fit additional debug information in memory. So memory corruption can sometimes go un-noticed when running a debug variant. So pretty much check for any stack/heap corruption that might be occuring in your code, because there's likely some memory over/underrun(s) happening somewhere.

Share this post


Link to post
Share on other sites
Quote:
Original post by Hodgman
Which compiler are you using?

You can try going into the compiler settings (Project properties in MSVC) and changing features such as Optimisation and run-time checking to be the same as debug (do one at a time) until you find a combination of settings that doesn't crash. This might give you a hint as to what is causing it.


I'm using Visual C# 08. The only option I saw was Optimization.

I looked through my code and saw no variables that aren't used or aren't initialized. Usually when a variable isn't set properly it'll throw an exception that the variable is null.

The DirectX error, I have no idea what it is. DebugView simplys dumps millions of lines of the same thing over and over with absolutely no useful information at all.


[2616] Direct3D9: (ERROR) : [0] : Address 035DE4CB
[2616]
[2616] Direct3D9: (ERROR) : [1] : Address 035DE59B
[2616]
[2616] Direct3D9: (ERROR) : [2] : Address 035DE440
[2616]
[2616] Direct3D9: (ERROR) : [3] : Address 035D2DB4
[2616]
[2616] Direct3D9: (ERROR) : [4] : Address 4FDFAF2E
[2616]
[2616] Direct3D9: (ERROR) : [5] : Address 00000000
[2616]
[2616] Direct3D9: (ERROR) : [6] : Address 00000000
[2616]
[2616] Direct3D9: (ERROR) : [7] : Address 00000000
[2616]
[2616] Direct3D9: (ERROR) : [8] : Address 00000000
[2616]
[2616] Direct3D9: (ERROR) : [9] : Address 00000000
[2616]
[2616] Direct3D9: (ERROR) : [10] : Address 00000000
[2616]
[2616] Direct3D9: (ERROR) : [11] : Address 00000000
[2616]
[2616] Direct3D9: (ERROR) : [12] : Address 00000000
[2616]
[2616] Direct3D9: (ERROR) : [13] : Address 00000000
[2616]
[2616] Direct3D9: (ERROR) : [14] : Address 00000000
[2616]
[2616] Direct3D9: (ERROR) : [15] : Address 00000000
...

Share this post


Link to post
Share on other sites

[2616] Direct3D9: (ERROR) : [0] : Address 035DE4CB
[2616]
[2616] Direct3D9: (ERROR) : [1] : Address 035DE59B
[2616]
[2616] Direct3D9: (ERROR) : [2] : Address 035DE440
[2616]
[2616] Direct3D9: (ERROR) : [3] : Address 035D2DB4
[2616]
[2616] Direct3D9: (ERROR) : [4] : Address 4FDFAF2E
[2616]
[2616] Direct3D9: (ERROR) : [5] : Address 00000000
[2616]
[2616] Direct3D9: (ERROR) : [6] : Address 00000000
[2616]
[2616] Direct3D9: (ERROR) : [7] : Address 00000000
[2616]
[2616] Direct3D9: (ERROR) : [8] : Address 00000000
[2616]
[2616] Direct3D9: (ERROR) : [9] : Address 00000000
[2616]
[2616] Direct3D9: (ERROR) : [10] : Address 00000000
[2616]
[2616] Direct3D9: (ERROR) : [11] : Address 00000000
[2616]
[2616] Direct3D9: (ERROR) : [12] : Address 00000000
[2616]
[2616] Direct3D9: (ERROR) : [13] : Address 00000000
[2616]
[2616] Direct3D9: (ERROR) : [14] : Address 00000000
[2616]
[2616] Direct3D9: (ERROR) : [15] : Address 00000000
...



Thats what it looks like when a DX-COM object doesn't have its ->Release() method called, probably because you are crashing before your deconstructers are called.

Share this post


Link to post
Share on other sites
Ok I got the logger working. I placed various writes throughout the game loop to try and pinpoint where it is. My findings are quite sparatic. The point at which it crashes seems to differ each time. Some times it crashes before it gets to the game loop, sometimes its able to render a good number of frames before crashing, and other times it crashes after one frame. Because its so random, I can't think of any good reason why its happening. Possibly something wrong with my computer? Can't be because I've played a game for an hour or two hours without issues.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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....

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :-)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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);
}
}
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Nothing in particular jumps out at me here, but I can take a look at it in detail if you'd like and your code fits in email (or if you want to upload it somewhere).

Share this post


Link to post
Share on other sites
Ok, I posted on MSDN and someone replied saying that the Windows.Form.Message does not include the time and pt members, so it was getting corrupted. They then pointed me to pinvoke.net which gave me a custom struct which fixed it. Thanks for your help all!


public static class NativeMethods
{
[StructLayout(LayoutKind.Sequential)]
public struct Message
{
public IntPtr handle;
public uint msg;
public IntPtr wParam;
public IntPtr lParam;
public uint time;
public System.Drawing.Point p;
}

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this