Yippee, Alt-Tabbing in MDX
I''m not going to switch it off, I''d just like to know what should I do when user presses Alt-Tab in FULLSCREEN mode?
I''ve tested all the mdx samples I found from the net (that use fullscreen mode) to discover that all they crash to an exception.
I''ve been playing around the DeviceLost and DeviceReset events and Reset method, but doing device reset in those just crashes even more badly
As long as you create everything in the MANAGED pool and make sure to release any swap chains first you should be fine calling reset.
public void ResetDevice() { VB.Dispose(); D3DDevice.Dispose(); D3DDevice = null; OneTimeInit(); Active = true; } protected override void OnGotFocus(EventArgs e) { base.OnGotFocus (e); if(D3DDevice != null) ResetDevice(); } protected override void OnSizeChanged(EventArgs e) { base.OnSizeChanged (e); if(D3DDevice != null) ResetDevice(); } public static void Main() { D3DBasicsA Frm = new D3DBasicsA () ; while(Frm.Created) { if(Frm.Active) { try { Direct3D.DeviceLostException.EnableExceptions(); Frm.Render(); System.Windows.Forms.Application.DoEvents(); } catch(Direct3D.DeviceLostException) { Frm.Active = false; } } else { Direct3D.DeviceLostException.IgnoreExceptions(); System.Windows.Forms.Application.DoEvents(); } } }
this is how i did it a while back, hope it helps.
I learned some things the hard way here. The SDK isn't as explicit as it could be.
If all your resources are in the managed pool, you're fine. When you call Present(), test for device lost. If you lost the device, keep spinning until you are able to get it back:
while (status != D3DERR_DEVICENOTRESET)
{
status = g_pMyDevice->TestCooperativeLevel();
Sleep(100);
MessagePump();
}
//get ready to reset the device here.
Now you know that your app is ready to reset the device.
Note that I found out the hard way that you must keep the message pump going here or your app will never come back to you.
Now, if you have resources in the nonmanaged pool, you must free them, then do a device reset, then reallocate your resources.
That's how I understand things, anyway. Hippie appears to be doing more destroy/recreate than is necessary.
[edited by - NogginBoink on December 28, 2003 1:13:20 AM]
If all your resources are in the managed pool, you're fine. When you call Present(), test for device lost. If you lost the device, keep spinning until you are able to get it back:
while (status != D3DERR_DEVICENOTRESET)
{
status = g_pMyDevice->TestCooperativeLevel();
Sleep(100);
MessagePump();
}
//get ready to reset the device here.
Now you know that your app is ready to reset the device.
Note that I found out the hard way that you must keep the message pump going here or your app will never come back to you.
Now, if you have resources in the nonmanaged pool, you must free them, then do a device reset, then reallocate your resources.
That's how I understand things, anyway. Hippie appears to be doing more destroy/recreate than is necessary.
[edited by - NogginBoink on December 28, 2003 1:13:20 AM]
Hmm, I just realized that I haven''t got this alt-tabbing working yet It seems that the SDK''s samples are the only programs that do handle alt-tabbing correctly with MDX. I just can''t find the spot. I had this once working when I used c++, but now I''m clueless what exceptions and functions should I check/call. Google didn''t find any decent examples
Business is business and Moses is Moses
[Homesite]
Business is business and Moses is Moses
[Homesite]
Ok, this is what I do:
When I alt-tab out from fullscreen mode, nothing happens yet. When I maximize the window back, I get exception from Application.DoEvents(). Exception is quite useless (Exception in application), but the stack trace goes through about 30 function calls ending at Direct3D''s Reset method. I''ve got no ideas...
Business is business and Moses is Moses
[Homesite]
public override void GameTick(){ graphics.Begin(System.Drawing.Color.Blue); graphics.End(); Application.DoEvents();}public void Begin(Color backgroundColor){ if(deviceIsLost) { try { device.TestCooperativeLevel(); } catch(DeviceLostException) { return; } catch(DeviceNotResetException) { device.Reset(pp); } deviceIsLost = false; } device.Clear(ClearFlags.Target, backgroundColor, 1.0f, 0); device.BeginScene();}public void End(){ if(!deviceIsLost) { device.EndScene(); try { device.Present(); } catch(DeviceLostException) { deviceIsLost = true; } }}
When I alt-tab out from fullscreen mode, nothing happens yet. When I maximize the window back, I get exception from Application.DoEvents(). Exception is quite useless (Exception in application), but the stack trace goes through about 30 function calls ending at Direct3D''s Reset method. I''ve got no ideas...
Business is business and Moses is Moses
[Homesite]
Silly, I haven''t got it working Really nobody knows how to do this?
Business is business and Moses is Moses
[Homesite]
Business is business and Moses is Moses
[Homesite]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement