MDX OnResize Exception

MickD

Newcomer
Joined
Jul 30, 2006
Messages
6
Location
Gerringong, NSW Australia
Hi All, I'm new to DirectX and have been studying the tut's in the sdk but have come across a small problem when resizing the form.
I noticed they handle Minimised in the OnResize override but when I size the window to nothing vertically it throws an exception. There is also code in place to handle pausing and reseting the device, these things I can understand but don't help.
I've searched high and low for a good explanation but so far I've come up short. I've seen code that handles the sizing of panels to prevent them from being (0,0) say but how do you handle a forms client rect?
I probably will move it to a panel anyway but I'd just like to work this one out first.
If you need to see some error reports or code, let me know but I don't think this is an isolated problem and hopefully I'm just missing something simple.
Thanks in advance for any help,
Cheers,
Mick.

Whoops, my appologies for posting in the wrong forum, could a mod make the changes if needed, thanks.
 
Why not set a minimum size for the form that would prevent the client rectangle from becoming zero-width or zero-height.
 
I tried setting the forms minimum size in the constructor but no go -
this.MinimumSize = new Size(1,1);

This is the error from the call stack -

MatricesTutorial.exe!MatricesTutorial.Matrices.OnResetDevice(System.Object sender = {Microsoft.DirectX.Direct3D.Device}, System.EventArgs e = null) Line 88

and here's the code where it's crashing when the app breaks -
Code:
public void OnResetDevice(object sender, EventArgs e)
		{
			Device dev = (Device)sender;
			// Turn off culling, so we see the front and back of the triangle
			dev.RenderState.CullMode = Cull.None;
			// Turn off D3D lighting, since we are providing our own vertex colors
			dev.RenderState.Lighting = false;// <---breaks here****
		}

Thanks for your speedy reply marble_eater :)
 
I've even tried something simple like this but it breaks before it happens I think??

Code:
protected override void OnResize(System.EventArgs e)
        {
            pause = ((this.WindowState == FormWindowState.Minimized) || !this.Visible || this.Size.Height < 2);//check height!
        }
 
The MinimumSize property sets the minimum values for the form's Size property, not the ClientSize property. You can either use a minimum size that is (almost) guarunteed to result in a client size at least one pixel, or you can calculate the minimum allowable size by getting the window border sizes from the SystemInformation class, and adding one to each pair of borders (left border size + right border size + 1 and top border size + bottom border size + 1).
 
Ok, I'll do a bit of study and let you know how I go, thanks again.

I've tested this on all tut's I've found so far and all have the same problem (all have different results for the errors though). I know it's probably not a common thing to do but I did it and it wouldn't be good for the end user to 'find' it either , and I just might learn something on the way
:)
 
A quick work around for now but doesn't solve the real issue, I set the minimum size to something like (30, 50) and it stopped it sizing too small, even though it was letting the height go much smaller than 50 when dragging the border!
There must be a way to tell the device or something that there's no client area to paint on and pause or something, I think I'm not catching the events quick enough, more study...
Cheers,
Mick.
 
Heres how I solved this problem in my app.

In the constructor of my Direct3D control, I hook up the’ DeviceResizing’ event

Code:
AddHandler Me.Device.DeviceResizing, AddressOf CancelResize

And the CancelResize sub:

Code:
Protected Sub CancelResize(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)

'If the window is to small or minimized, cancel the resize event to prevent crashing.
 If Me.Width = 0 OrElse Me.Height = 0 Then
        e.Cancel = True
 End If

End Sub
 
Back
Top