# Viewport and debug session

I define and set viewport using this piece of code:

D3D11_VIEWPORT viewport;

viewport.Width = (FLOAT)pBspWindow->GetWidth();
viewport.Height = (FLOAT)pBspWindow->GetHeight();
viewport.TopLeftX = 0.0f;
viewport.TopLeftY = 0.0f;
viewport.MaxDepth = 1.0f;
viewport.MinDepth = 0.0f;



If I remove MaxDepth/MinDepth members and run my application under debug session triangle will not be shown.

This behaviour doesn't appear under release session.

I searched on MSDN, but couldn't find anything.

I'm interested why is this happening?

You rely on uninitialized state. D3D11_VIEWPORT is a POD type, without any constructors or so. In this case, you can get different result each time your app runs.
In Debug mode, compilers initialize variables in different manner - they use Magic Debug Values, add guard bytes and much more to check for validity of your code. For instance, if you check values of your uninitialized viewport under debug session, you will probably see -107374176, which is ~0x06666660 + 1. Probably it is a value chosen by MS to flag uninitialized floating point numbers.
• Note that if you use CD3D11_VIEWPORT, the C++ wrapper for D3D11_VIEWPORT, then it has a constructor and does initialize the struct. Jul 30 '15 at 0:18