1
我正在使用Microsoft.DirectX和Microsoft.DirectX.Direct3D引用在我的窗體上執行一些繪圖。當我運行該程序並且用戶在Windows XP中按下CTRL ALT DEL並彈出「Windows安全性」窗體時,在返回到窗體時會拋出DeviceLostException,並且在嘗試處理此異常時似乎沒有辦法把它拿回來。使用C#在Direct3D中CTRL ALT DEL期間的DeviceLostException
我對這件事做了一點研究,並嘗試了幾種編碼解決方案。
try
{
_d3ddevice.Present();
}
catch
{
DeviceLost = true;
}
if (DeviceLost)
{
AttemptRecovery();
}
this.Invalidate();
ReadKeyboard();
base.OnPaint(e);
}
private void AttemptRecovery()
{
try
{
_d3ddevice.TestCooperativeLevel();
}
catch (DeviceLostException)
{
Application.Exit();
}
catch (DeviceNotResetException)
{
try
{
_d3ddevice.Reset(_params);
DeviceLost = false;
InitGraphics();
CameraPositioning();
VertexDeclaration();
IndicesDeclaration();
}
catch (DeviceLostException)
{
}
}
}
當程序調用TestCooperativeLevel(),它在網上表示,如果再次捕獲DeviceLostException有在嘗試重置設備沒有意義。
我能做些什麼來重置設備並繼續在我的表單中繪圖?
此行爲已記錄。丟失設備有幾個原因,您必須等到您可以創建一個新設備。這是許多遊戲(歷史上)在你退出遊戲時會崩潰的主要原因(alt-tab,alt-enter,ctrl-alt-del,popups等)。 – 2011-04-29 22:44:26