news:1179420562.665157.171750@o5g2000hsb.googlegro ups.com...
Quote:
Here is a sample code that demonstrates the problem.
To build and run this code you will require DirectX SDK installed on
your system.
>
Follow the steps below to reproduce the problem.
1.) Create a new Windows Application project in Visual Studio 2003
(the code will also work in 2005)
2.) Open the default Form1 in 'Code View'
3.) Replace the code of Form1 with the code specified below
4.) Add references to DirectX, Direct3D, and Direct3DX dlls.
5.) Run the App
6.) Press TestTimeSpan button to see the output from TimeSpan
structure and my calculations.
7.) Press Create Device button to create a new DirectX device object.
8.) Again press TestTimeSpan button
HERE YOU WILL SEE THE PROBLEM IN THE TIMESPAN STRUCTURE.
NOTICE THE DIFFRENCE BETWEEN Ticks and TotalSeconds properties.
>
>
*****************************CODE
(form1.cs)****************************
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Direct3D = Microsoft.DirectX.Direct3D;
using System.Diagnostics;
>
namespace TestNamespace
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Button btn_TestTimeSpan;
private System.Windows.Forms.Button btnCreateDevice;
private System.Windows.Forms.Button btnDisposeDevice;
private System.Windows.Forms.TextBox txtOutput;
private Device device = null;
>
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
>
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
>
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btn_TestTimeSpan = new System.Windows.Forms.Button();
this.btnCreateDevice = new System.Windows.Forms.Button();
this.btnDisposeDevice = new System.Windows.Forms.Button();
this.txtOutput = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// btn_TestTimeSpan
//
this.btn_TestTimeSpan.Location = new System.Drawing.Point(0,
48);
this.btn_TestTimeSpan.Name = "btn_TestTimeSpan";
this.btn_TestTimeSpan.Size = new System.Drawing.Size(104,
32);
this.btn_TestTimeSpan.TabIndex = 0;
this.btn_TestTimeSpan.Text = "Test TimeSpan";
this.btn_TestTimeSpan.Click += new
System.EventHandler(this.btn_TestTimeSpan_Click);
//
// btnCreateDevice
//
this.btnCreateDevice.Location = new System.Drawing.Point(0,
8);
this.btnCreateDevice.Name = "btnCreateDevice";
this.btnCreateDevice.Size = new System.Drawing.Size(104, 32);
this.btnCreateDevice.TabIndex = 1;
this.btnCreateDevice.Text = "Create Device";
this.btnCreateDevice.Click += new
System.EventHandler(this.btnCreateDevice_Click);
//
// btnDisposeDevice
//
this.btnDisposeDevice.Location = new
System.Drawing.Point(112, 8);
this.btnDisposeDevice.Name = "btnDisposeDevice";
this.btnDisposeDevice.Size = new System.Drawing.Size(104,
32);
this.btnDisposeDevice.TabIndex = 2;
this.btnDisposeDevice.Text = "Dispose Device";
this.btnDisposeDevice.Click += new
System.EventHandler(this.btnDisposeDevice_Click);
//
// txtOutput
//
this.txtOutput.Location = new System.Drawing.Point(8, 96);
this.txtOutput.Multiline = true;
this.txtOutput.Name = "txtOutput";
this.txtOutput.ScrollBars =
System.Windows.Forms.ScrollBars.Both;
this.txtOutput.Size = new System.Drawing.Size(656, 408);
this.txtOutput.TabIndex = 3;
this.txtOutput.Text = "";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(672, 518);
this.Controls.Add(this.txtOutput);
this.Controls.Add(this.btnDisposeDevice);
this.Controls.Add(this.btnCreateDevice);
this.Controls.Add(this.btn_TestTimeSpan);
this.FormBorderStyle =
System.Windows.Forms.FormBorderStyle.SizableToolWi ndow;
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
>
}
#endregion
>
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
try
{
using (Form1 frm = new Form1())
{
frm.Show();
Application.Run(frm);
}
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show("Problem in
application, will now exit. " + e.Message);
}
}
>
private void CreateDevice()
{
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
presentParams.AutoDepthStencilFormat = DepthFormat.D16;
presentParams.EnableAutoDepthStencil = true;
>
device = new Device(0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing, presentParams);
}
private void DisposeDevice()
{
device.Dispose();
}
public void TimeSpanProblem(string strFrom)
{
DateTime dt1970 = new DateTime(1970, 1, 1);
//LoadVC();
System.TimeSpan tss = DateTime.Now - dt1970;
uint nT11 = (uint)(tss.Ticks / TimeSpan.TicksPerSecond);
uint nT1 = (uint)tss.TotalSeconds;
uint nT2 = (uint)(tss.Ticks - (nT1 *
TimeSpan.TicksPerSecond));
string displayStr = "@@@@@@@@@"+strFrom+"@@@@@@@@@";
if (nT1 != nT11)
{
displayStr += Environment.NewLine +
"************************************************* *******"
+ Environment.NewLine + "PROBLEM!! T1 != T11 (NOTICE
THAT THE DECIMALS ARE GONE FOR TotalSeconds)"
+ Environment.NewLine +
"************************************************* *******";
}
else
{
displayStr += Environment.NewLine +
"************************************************* *******"
+ Environment.NewLine + "Everything OK!!"
+ Environment.NewLine +
"************************************************* *******";
}
>
displayStr+=
Environment.NewLine + "------TimeSpan---------"
+ Environment.NewLine + "tss.Ticks
=
{0}"
+ Environment.NewLine + "tss.TotalSeconds
=
{1}"
+ Environment.NewLine + "------My Variables---------"
+ Environment.NewLine + "T1 = (uint)tss.TotalSeconds
= {2}"
+ Environment.NewLine + "T2 = (uint)(tss.Ticks - (nT1
* TimeSpan.TicksPerSecond)) = {3}"
+ Environment.NewLine + "T11 = (uint)(tss.Ticks /
TimeSpan.TicksPerSecond) = {4}"
+ Environment.NewLine +
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~"+Environment.NewLine
+Environment.NewLine+Environment.NewLine;
>
txtOutput.Text +=
String.Format(displayStr,tss.Ticks,tss.TotalSecond s,nT1,nT2,nT11);
txtOutput.Select(txtOutput.Text.Length-2,1);
txtOutput.ScrollToCaret();
}
>
private void btn_TestTimeSpan_Click(object sender,
System.EventArgs e)
{
this.TimeSpanProblem("From btn_TestTimeSpan_Click");
}
>
private void btnCreateDevice_Click(object sender,
System.EventArgs e)
{
CreateDevice();
}
>
private void btnDisposeDevice_Click(object sender,
System.EventArgs e)
{
DisposeDevice();
}
>
}
}
>
*****************************CODE
END**********************************
>
>
I can confirm the issue. The problem is with DirectX resetting the X87
FPU to single precision mode by resetting the FCW to 7Fh.
expects the FPU to be in double precision mode. The point is who to blame?
DX or the CLR? I would suggest you to do as Peter said, file a bug. In the
class.
Willy.
Willy.