0
\$\begingroup\$

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;

pD3DContext->RSSetViewports(1, &viewport);

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?

\$\endgroup\$
0
\$\begingroup\$

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.

In release version, none of this happens - all additional checks are disabled. So you probably hit a values, that are valid for D3D. Coincidence.

Basically, you can classify that (using variables, that were not initialized) as undefined behaviour.

\$\endgroup\$
2
  • \$\begingroup\$ It make sense if you want to debug your code regardless of whether it is a D3Dx app or a classic stuff. I had to ask because I scratched my head for a while looking for a solution :). thnx \$\endgroup\$ Jul 29 '15 at 12:39
  • \$\begingroup\$ Note that if you use CD3D11_VIEWPORT, the C++ wrapper for D3D11_VIEWPORT, then it has a constructor and does initialize the struct. \$\endgroup\$ Jul 30 '15 at 0:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .