Sign in to follow this  
jdub

[SlimDX] C# debugging in a release build

Recommended Posts

I have a program that works when I build it in debug mode but crashes in the release build. How can I be able to set break points and debug in a release build? [Edited by - jdub on November 26, 2008 6:55:35 PM]

Share this post


Link to post
Share on other sites
If you launch via the debugger you'll still be able to debug the release build. This is because the debugger can tell it to suppress JIT optimizations.

If you run a release build and then try to attach, that's the point at which you're hosed.

Share this post


Link to post
Share on other sites
Quote:
Original post by jdub
So I guess to debug, I have to pick through the code by hand and see where there are uninitiallized primitives or something like that?


No, because .NET doesn't have primitives. Even the 'primitive' types are such int, float, long, etc. are object instances. The keyword int is just short for Int32.

.NET initializes all variables before execution, so you can be 100% assured that there are no uninitialized variables. They're either 0, or null.

Toolmaker

Share this post


Link to post
Share on other sites
Quote:
Original post by Toolmaker
Quote:
Original post by jdub
So I guess to debug, I have to pick through the code by hand and see where there are uninitiallized primitives or something like that?


No, because .NET doesn't have primitives. Even the 'primitive' types are such int, float, long, etc. are object instances. The keyword int is just short for Int32.

.NET initializes all variables before execution, so you can be 100% assured that there are no uninitialized variables. They're either 0, or null.

Toolmaker


Except locals, which you must explicitly initialise or receive a compile error, either way if your program runs, there are no uninitialised variables.

Share this post


Link to post
Share on other sites
Quote:
Original post by jdub
So then why would the program be crashing?

It's not crashing, it's throwing an exception that you're not handling. Short of seeing the exception and possibly some code there is practically no possibility of us telling you why your application is failing.

Share this post


Link to post
Share on other sites
Okay here is the code:

This function updates one frame:

private void RenderAndUpdateScene()
{
try
{
//if the device is lost, free up some CPU time and call deviceLost()
if (graphicsDevice.TestCooperativeLevel () == ResultCode.DeviceLost)
{

MessageBox.Show ( "Device Lost" );
this.deviceLost ();
Thread.Sleep ( 100 );
return;
}

//The graphics device can be restored so try and do it
if (graphicsDevice.TestCooperativeLevel () == ResultCode.DeviceNotReset)
{
// if we can reset then try it, and if it fails, something bad has happened
if (graphicsDevice.Reset ( presentParams ).IsSuccess)
{
this.deviceReset ();
return;
}

if (graphicsDevice.TestCooperativeLevel () == ResultCode.DriverInternalError)
{
Application.Exit ();
}
}
else
{
gameTimer.Update ();


//Render GameViews here

if (gameTimer.IsTimeToRender)
{
this.Render ( gameTimer.EllapsedMilliseconds, gameTimer.TotalMilliseconds );


UpdateGame ( gameTimer.EllapsedMilliseconds, gameTimer.TotalMilliseconds );

}

}
}
catch(NullReferenceException e)
{
MessageBox.Show ( e.ToString() );
}
}




This is the function that creates my Device:

public static Result CreateGraphicsDevice(ref Device device, GameWindow gameWindow, WindowParameters windowParams)
{
bool result;
PresentParameters presentParams = new PresentParameters ();
Format fullscreenFormat = Format.X8R8G8B8;
DeviceType deviceType = DeviceType.Hardware;

DisplayMode dMode = direct3D.EnumerateAdapterModes ( 0, fullscreenFormat, 0 );


if (windowParams.FullScreen)
{
presentParams.BackBufferFormat = fullscreenFormat;
presentParams.BackBufferWidth = dMode.Width;
presentParams.BackBufferHeight = dMode.Height;
presentParams.FullScreenRefreshRateInHertz = dMode.RefreshRate;
presentParams.Windowed = false;
presentParams.PresentationInterval = PresentInterval.One;

bool multisample = direct3D.CheckDeviceMultisampleType ( 0,
DeviceType.Hardware,
Format.X8R8G8B8,
false,
MultisampleType.TwoSamples );

if (multisample)
{
presentParams.Multisample = MultisampleType.TwoSamples;
}
}
else
{
presentParams.BackBufferFormat = Format.Unknown;
presentParams.BackBufferHeight = gameWindow.gameForm.Size.Height;
presentParams.BackBufferWidth = gameWindow.gameForm.Size.Width;
presentParams.Windowed = true;
presentParams.Multisample = MultisampleType.None;
}

presentParams.BackBufferCount = 2;

presentParams.DeviceWindowHandle = gameWindow.gameForm.Handle;

presentParams.SwapEffect = SwapEffect.Discard;

result = direct3D.CheckDeviceType ( 0,
deviceType,
fullscreenFormat,
fullscreenFormat,
windowParams.FullScreen );

//if the adapter doesn't support hardware, create a software device
if (!result)
{
device = new Device ( direct3D,
0,
DeviceType.Software,
gameWindow.gameForm.Handle,
CreateFlags.SoftwareVertexProcessing,
presentParams );

return ResultCode.Success;
}

device = new Device (direct3D,
0,
deviceType,
gameWindow.gameForm.Handle,
CreateFlags.SoftwareVertexProcessing,
presentParams );

gameWindow.presentParams = presentParams;

return ResultCode.Success;
}




I don't know what is wrong. The application renders succesfully and updates. But after leaving leaving this loop in my Application.Idle event handler:

DllImport ( "User32.dll" )]
[return: MarshalAs ( UnmanagedType.Bool )]
static extern bool PeekMessage(out Message msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);

private static bool stillIdle
{
get
{
Message msg;
return !PeekMessage ( out msg, IntPtr.Zero, 0, 0, 0 );
}
}

public void OnIdle(object sender, EventArgs args)
{
while(stillIdle)
{
RenderAndUpdateScene();
}
}




also my class to manage frame timing:


public class GameTimer
{
private long totalMilliseconds = 0;
private Stopwatch frameTimer = null;
private bool isFirstUpdate = true;

public bool IsTimeToRender
{
get
{

if (frameTimer.ElapsedMilliseconds >= 1000 / 60)
{
return true;
}

return false;
}
}

public long EllapsedMilliseconds
{
get { return frameTimer.ElapsedMilliseconds; }
}

public long TotalMilliseconds
{
get { return totalMilliseconds; }
}

public GameTimer()
{
frameTimer = new Stopwatch ();
}

public void Update()
{
//if it is the first update, start the frame timer
if (isFirstUpdate)
frameTimer.Start ();

//if it is over the rate of the fps we want then reset the time and add the ellapsed to our total milliseconds
if (frameTimer.ElapsedMilliseconds >= (1000 / 60) )
{

this.totalMilliseconds += frameTimer.ElapsedMilliseconds;
frameTimer.Reset ();
}
}
}



When I run in release mode, I don't catch any exceptions. The application just crashes.

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