FullScreen Problem

Started by
1 comment, last by muster 16 years, 6 months ago
Hello there. I've faced many problems in getting the fullscreen device lost-reset to work but still there is a problem that when I alt-tab and restore the first time the application works fine but doing this again will cause the application to halt and the device fail to reset. I've noticed a memory overflow which can be solved by flags for reset but it won't fix the problem ofcourse. Here is the code can u take a look at my code and I'll be very gratefull if u find the error and give me a good solution. Note i used device resising cancel event and nothing is changed. To download the code go to this link=(canceled and the code is down below) Thanks in advance... [Edited by - muster on September 29, 2007 4:16:47 AM]
Advertisement
What debugging have you done?

Have you compared your lost-device handling code with that in DXUT? Followed all the guidelines in the SDK documentation?

Have you traced your app using PIX to see what resources are still alive at a given point?

You'll almost certainly have to post some of your code in [source][/source] tags (but only the absolutely essential fragments - no code dumps please!) along with all relevant state information (current variables, error codes etc..) as very few people will ever download arbitrary code from the internet. It's just far too dangerous.


hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

hello again. I've found the problem but don't know how to solve it. The problem is that when the device resets in fullscreen mode everything works fine without any vertices being drawn, but by inserting vertices and rendering them the previous problem happens. here is the code, I'll be glad if someone can give a good solution for this.
using System;using System.Drawing;using System.Windows.Forms;using System.Diagnostics;using Microsoft.DirectX;using Microsoft.DirectX.Direct3D;namespace FullScreen{    public class FS : System.Windows.Forms.Form    {        private static FS app;        private Device device;        private VertexBuffer vertices;        private bool deviceLost;        private PresentParameters pres = new PresentParameters();        static void Main()        {            app = new FS();            app.InitializeComponent();            app.InitializeGraphics();            app.Show();            app.KeyPress += new KeyPressEventHandler(app_KeyPress);            while (app.Created)            {                app.Render();                Application.DoEvents();            }        }        private void Quit()        {            System.Threading.Thread th = new System.Threading.Thread(doQuit);            th.Start();        }        public void doQuit()        {            System.Diagnostics.Process.GetCurrentProcess().Kill();        }        static void app_KeyPress(object sender, KeyPressEventArgs e)        {            if (e.KeyChar == (System.Char)27)                ((FS)sender).Quit();        }        protected bool InitializeGraphics()        {            this.KeyPress += new KeyPressEventHandler(Game_KeyPress);            Microsoft.DirectX.Direct3D.Caps caps = Microsoft.DirectX.Direct3D.Manager.GetDeviceCaps(Microsoft.DirectX.Direct3D.Manager.Adapters.Default.Adapter,                                               Microsoft.DirectX.Direct3D.DeviceType.Hardware);            Microsoft.DirectX.Direct3D.CreateFlags flags;            if (caps.DeviceCaps.SupportsHardwareTransformAndLight)                flags = Microsoft.DirectX.Direct3D.CreateFlags.HardwareVertexProcessing;            else                flags = Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing;            pres.BackBufferCount = 1;            pres.BackBufferWidth = this.ClientSize.Width;            pres.BackBufferHeight = this.ClientSize.Height;            pres.PresentationInterval = PresentInterval.Immediate;            pres.AutoDepthStencilFormat = DepthFormat.D16;            pres.DeviceWindow = this;            pres.MultiSample = MultiSampleType.None;            pres.SwapEffect = SwapEffect.Discard;            pres.BackBufferFormat = Format.A8R8G8B8;            pres.Windowed = false;            device = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, this, flags, pres);            device.DeviceResizing += new System.ComponentModel.CancelEventHandler(this.CancelResize);            device.DeviceReset += new EventHandler(this.OnDeviceReset);            device.DeviceLost += new EventHandler(this.OnDeviceLost);            SetupDevice();            return true;        }        void CancelResize(object sender, System.ComponentModel.CancelEventArgs e)        {            if(!device.PresentationParameters.Windowed)                e.Cancel = true;        }        void Game_KeyPress(object sender, KeyPressEventArgs e)        {            if (e.KeyChar == (char)27)                Environment.Exit(0);        }        protected void OnDeviceReset(object sender, EventArgs e)        {            SetupDevice();        }        protected void OnDeviceLost(object sender, EventArgs e)        {            vertices.Dispose();        }        protected void SetupDevice()        {            device.RenderState.Lighting = false;            device.RenderState.CullMode = Cull.None; pres.BackBufferCount = 1;                        vertices = CreateVertexBuffer(device);        }        protected VertexBuffer CreateVertexBuffer(Device device)        {            VertexBuffer buf = new VertexBuffer(              typeof(CustomVertex.PositionColored), // What type of vertices              3,                                    // How many               device,                               // The device              0,                                    // Default usage              CustomVertex.PositionColored.Format,  // Vertex format              Pool.Default);                        // Default pooling            CustomVertex.PositionColored[] verts =(CustomVertex.PositionColored[])buf.Lock(0, 0);            int i = 0;            verts[i++] = new CustomVertex.PositionColored(              0, 1, 0, Color.Red.ToArgb());            verts[i++] = new CustomVertex.PositionColored(              -0.5F, 0, 0, Color.Green.ToArgb());            verts[i++] = new CustomVertex.PositionColored(              0.5F, 0, 0, Color.Blue.ToArgb());            buf.Unlock();            return buf;        }        protected void SetupMatrices()        {            float angle = Environment.TickCount / 500.0F;            device.Transform.World = Matrix.RotationY(angle);            device.Transform.View = Matrix.LookAtLH(new Vector3(0, 0.5F, -3),new Vector3(0, 0.5F, 0), new Vector3(0, 1, 0));            device.Transform.Projection =Matrix.PerspectiveFovLH((float)Math.PI / 4.0F, 1.0F, 1.0F, 5.0F);        }        protected void Render()        {            if (deviceLost)                AttemptRecovery();            if (deviceLost)                return;            device.Clear(ClearFlags.Target, Color.Bisque, 1.0F, 0);            device.BeginScene();            SetupMatrices();            device.VertexFormat =CustomVertex.PositionColored.Format;            device.SetStreamSource(0, vertices, 0);            device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);            device.EndScene();            try            {                device.Present();            }            catch (DeviceLostException)            {                deviceLost = true;                Debug.WriteLine("Device was lost");            }        }        protected void AttemptRecovery()        {            try            {                device.TestCooperativeLevel();            }            catch (DeviceLostException)            {                deviceLost = true;            }            catch (DeviceNotResetException)            {                try                {                    device.Reset(pres);                    deviceLost = false;                }                catch (Exception)                {                    // If it's still lost or lost again, just do                     // nothing                }            }        }        private void InitializeComponent()        {            this.SuspendLayout();            this.ClientSize = new System.Drawing.Size(1024,768);            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;            this.Name = "Game";            this.ResumeLayout(false);        }    }}


[Edited by - muster on September 29, 2007 9:14:28 AM]

This topic is closed to new replies.

Advertisement