Forum
Contact





DirectX using C#
DirectX using C++
DirectX using Visual Basic



Latest Forum posts

 Suggestion to change a few lines
  Posted by: Insomnica
  When: 06/09/2010 at 14:37:05

 Collision with series 1
  Posted by: radulph
  When: 05/09/2010 at 13:33:14

 HLSL calculating normals
  Posted by: miroslavign
  When: 04/09/2010 at 17:26:26

 Collision with series 1
  Posted by: ToastbrotX
  When: 04/09/2010 at 16:52:02

 HLSL calculating normals
  Posted by: Rich_Zap
  When: 04/09/2010 at 15:00:20

 Collision with series 1
  Posted by: ToastbrotX
  When: 04/09/2010 at 12:28:41

 HLSL calculating normals
  Posted by: miroslavign
  When: 04/09/2010 at 08:46:31

 Walk along a wall
  Posted by: Anonymous
  When: 03/09/2010 at 10:28:02

 model problems
  Posted by: muffinman
  When: 03/09/2010 at 06:47:32

 Vertices problem
  Posted by: Anonymous
  When: 03/09/2010 at 05:48:35

 OcTree Question
  Posted by: Zorzomezz
  When: 03/09/2010 at 04:07:03

 error x3000:syntax error
  Posted by: Anonymous
  When: 02/09/2010 at 06:55:17

 Reflection problem in corners ...
  Posted by: Anonymous
  When: 31/08/2010 at 20:53:30

 OcTree Question
  Posted by: radulph
  When: 31/08/2010 at 18:00:04

 model problems
  Posted by: Archenon
  When: 30/08/2010 at 05:54:27

 Changing computer breaks my game
  Posted by: Archenon
  When: 30/08/2010 at 05:49:50

 model problems
  Posted by: muffinman
  When: 28/08/2010 at 16:58:10

 Vertices problem
  Posted by: Anonymous
  When: 27/08/2010 at 15:35:36

 Changing computer breaks my game
  Posted by: radulph
  When: 27/08/2010 at 07:12:24

 effects file and XNA 4.0 (Beta)
  Posted by: radulph
  When: 26/08/2010 at 06:33:33




Topic: Doesn't draw after resizing



  
Goto parent category
  
Create a new user account


   Doesn't draw after resizing
 Poster : thkoe002
 Posts: 17
 Country : Germany
 City: Düsseldorf

  
Posted by thkoe002 on 18/07/2006 at 22:11:55
Hi there.
First of all, thanks alot for your detailed tutorial. It must have been a great deal of work, but I'm sure everyone who reads it appreciates it alot.
As for me, I currently won't need meshes and lights (for now), but only simple wireframe structures. My problem is that, despite having this.Invalidate() in my OnPaint() method and this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true) after the InitializeDevice(), anytime I resize the window (by dragging with the mouse or by clicking the maximize-button), the window goes (and stays) black. Any ideas what I could be doing wrong? I use c# express 2005.
Thanks, cheers
Thomas

PS. I also tried to add ControlStyles.ResizeRedraw to the SetStyle options, no luck...
 Poster : NoonienSoong
 Posts: 76
 Country : usa
 City: cleveland

  
Posted by NoonienSoong on 19/07/2006 at 04:13:58
hopefully when Riemer returns we'll get the whole story, but I've had that problem and the way I've dealt with it is to reinitialize everything after a resize when in windowed mode. I posted a description of this process in another thread.

I'm hoping there is a simpler solution, but currently I'm not aware of it.

It's basically releasing your resources, rebuilding your PresentParams, calling device.Reset, and reloading your resources. Yes it is quite a drag.

It's funny because I have some DirectX programs that don't require this procedure. I wrote a little DirectX app simply for testing little effects and the resizing would be fine until I made some seemingly insignificant change. It's weird.
 Poster : riemer
 Posts: 1388
 Country : Belgium
 City: Antwerp

  
Posted by riemer on 30/07/2006 at 16:00:45
Nice you discovered this. Probably I should have included this in my tutorials, but it uses something C#/DirectX specific, and my main goals is to keep the tutorials as general as possible.

What is happening, is that the device gets 'lost' whenever you change something about its host, the form. In case of fullscreen apps, the device gets lost when you switch to another application.

When a device gets lost, it clears all of its resources, such as vertex- and indexbuffers. When the DX app regains focus, it gets 'reset', and its buffers are automatically re-created (if they are created in the Managed memory pool). However, the data will NOT be restored, so you get empty buffers.

In the case of a resize (and Managed resources), you get that your device gets lost (buffers emptied and discarded) and gets reset immediately thereafter (empty buffers recreated). In short, your buffers are emptied :)

So what you need to do (here comes the C# part), is add an Event to reload all you buffer data. In later chapters, I've grouped this code together in the VertexDeclaration method. The next line will run that method automatically after the device gets reset:


vb.Created += new EventHandler(this.VertexDeclaration);


Add this line after your device creation. It will trigger the VertexDeclaration method whenever the buffer gets re-created. The same holds for our indexbuffer:


ib.Created += new EventHandler(this.IndidesDeclaration);


Which will refill your index buffer when it gets automatically recreated after a device reset.



hmmm Should I have added this part to the tutorial ?
 Poster : thkoe002
 Posts: 17
 Country : Germany
 City: Düsseldorf

  
Posted by thkoe002 on 31/07/2006 at 02:41:03
Hi Riemer! Hope you had a good vacation.
Concerning this problem, thanks for clearing this up... but unfortunately, I get the following error message when pasting the code into my project: "No overload for 'VertexDeclaration' matches delegate 'System.EventHandler'" (http://img255.imageshack.us/img255/739/07312006093925js0.png), what could be wrong this time?
And yes I think it would be a good idea to add this to the tutorial... do you also have an explanantion why sometimes the resize works even without this modification? Like NoonienSoong, my application had no problem with resizing until I made a couple of unsignificant changes (that I, alas, don't even remember)... cheers,
Thomas
 Poster : bikelink
 Posts: 1
 Country : italy
 City: verona

  
Posted by bikelink on 18/10/2006 at 05:16:11
I don't know why the code don't repaint correctly the triangle. I'll guess a fix geometry... instead the triangle is streched..while the window is resized (only in one dimension..)

this is my code..:


protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        
    {
           device.Clear(ClearFlags.Target, Color.DarkSlateBlue, 1.0f, 0);
            

           device.BeginScene();
            

            // Draw triangle...
            DisegnaTriangolo();
            

            device.VertexFormat = CustomVertex.TransformedColored.Format;
            device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices);
    

            device.EndScene();

            
            device.Present();

         this.Invalidate();
    }

    public WinForm()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
        }
 Poster : Anonymous
 Posts:
 Country :
 City:

  
Posted by Anonymous on 18/10/2006 at 05:24:36
ops...i saw just now. ;)
http://www.riemers.net/ShortTuts/lost_device.php
 Poster : Anonymous
 Posts:
 Country :
 City:

  
Posted by Anonymous on 03/01/2007 at 11:19:01
Note that part of the problem is that the form's resize event is not being handled.  If you add an event handler for the resize event and have it call form.Invalidate(), then the form will be repainted at the new size.

                      Mark
 Poster : riemer
 Posts: 1388
 Country : Belgium
 City: Antwerp

  
Posted by riemer on 04/01/2007 at 14:22:51
Thanks for the addition Mark!

  
Post a new reply
 





Google
 
Web www.riemers.net
If you appreciate the amount of time I spend creating and updating
these pages, feel free to donate -- any amount is welcome !
- Website design & DirectX code : Riemer Grootjans -
©2006 Riemer Grootjans


News
Home
Forum
XNA 2.0 Recipes Book (8)
XNA 3.0 Recipes Book (8)
Downloads
Extra Reading (3)
Matrices: geometrical
Matrix Mathematics
Homogenous matrices
Community Projects (1)
Tutorials (160)
XNA 3.0 using C# (89)
DirectX using C# (54)
Series 1:Terrain (14)
Opening a window
Linking to the Device
Drawing a triangle
Camera
Rotation - Translation
Indices
Terrain creation
Terrain from file
DirectInput
Importing bmp files
Colored vertices
DirectX Light basics
Mesh creation
Mesh lighting
Series 2: Flightsim (19)
Series 3: HLSL (19)
Short Tuts (2)
Resizing problem
Checking Device caps
DirectX using C++ (15)
DirectX using VB (2)