Hello, I have this little Direct3D application, I have a little bug so I'm trying to debug it with the MSVC debugger.
First of all I have this code:
.h file
#include <windows.h>
...
class CGame
{
...
D3DPRESENT_PARAMETERS d3dpp;
...
};
.cpp file
...
ZeroMemory(&d3dpp, sizeof(d3dpp));
if (FULLSCREEN)
d3dpp.Windowed = FALSE;
else
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
if
(FULLSCREEN) d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
else
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferWidth = APP_WIDTH;
d3dpp.BackBufferHeight = APP_HEIGHT;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.Flags = 0;
d3dpp.hDeviceWindow = hWnd;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.MultiSampleQuality = 0;
if (FAILED(d3dObject->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &d3dDevice)))
{
logger.Log("d3dDevice creation failed");
return E_FAIL;
}
...
So first of all I suspect that d3dpp somehow doesn't set all its variables as I try to do.
If I comment all the d3dpp.<variable> = <value> lines. The application will generate an error at the "if (FAILED(d3dObject->CreateDevice()))" line, since it needs the d3dpp to be correctly setup.
First of all I put a breakpoint at the ZeroMemory(&d3dpp, sizeof(d3dpp)); line and at the if (FAILED(d3dObject->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL ... line. I start debug mode in MSVC and add a watch (or look at the auto watch window) for d3dpp. Before the ZeroMemory line, it's just pure garbage. Then I press F5 to jump down to next breakpoint, which is the if (FAILED(d3d.... one. Now the watch (and the auto watch of c) shows all 0:s everywhere. For example for d3dpp.BackBufferWidth, it shows 0. The auto watch shows that APP_WIDTH = 1280 and just a couple of lines up I have d3dpp.BackBufferWidth = APP_WIDTH. So by watching the d3dpp in the watch and auto watch windows I could say that all the lines between (all the d3dpp.<variable> = <value> lines) have not been executed. However, the d3dObject->CreateDevice succeeds and if I compile and run without the d3dpp.<variable> = <value> lines it does _not_ succeed so clearly the lines has been executed.
So I tried to just put a breakpoint on for example d3dpp.BackBufferWidth = APP_WIDTH. Then when I run the debugger, the red dot indicating breakpoint gets a question mark on it, and it says "Invalid line". And the same applies for _all_ lines between ZeroMemory and if (FAILED(d3dObject->
So my questions are:
1. WHY does auto watch and watch windows show that d3dpp isn't set (they only show 0:s for all values).
2. WHY would all those lines that sets up the d3dpp structure be "invalid"? So I can't breakpoint them?
I don't know if this is some special Direct3D thing but it seems more like a MSVC thing.
Any help appreciated, I'm new to this stuff :)
EDIT: If you read this far and somewhat understood my nonsense: Yes, if I leave it as it is, there is no problem. It's just that later in the program the d3dpp structure is again all zeros, and then a call fails because of that. So I need to find where and why the d3dpp structure is cleared / corrupted. And that would be easy with the debugger, by first letting the debugger set for example d3dpp.BackBufferWidth to 1280, then set a breakpoint to "break when d3dpp.BackBufferWidth changes". As it is now, the debugger says it's 0 all the time and it'll never change :S