MSVC debugger problem

Started by
3 comments, last by ZQJ 18 years, 9 months ago
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
Advertisement
I may be wrong, but do you not have to set the size parameter of D3DPRESENT_PARAMETERS before you can use it?
I don't believe that is the issue and all other code examples / tutorials I've found does nothing of such. And just to clarify, this code _works_ flawlessly. Its in a complete other part of the project that this d3dpp structure is corrupt and no longer working as it does in this part of the project. Something have happened to it and since I don't touch it anywhere else I really would like the debugger to track it for changes. That is not possible since the debugger seems to skip those d3dpp.<variable> = <value> lines.
It sounds like you need to fully rebuild your project. If that doesn't help, then d3dpp has probably gone out of scope when you are trying to debug or use it. From a look, I can't see any obvius errors in the posted code.
Well I'm guessing you're compiling in release mode, and presumably filling all of the fields in the d3dpp structure. That means the compiler could do all sorts of things but the most likely I think would be that it has a copy of the resultant structure in the constant data area and memcpy()s it onto the stack at a different location to the d3dpp used by ZeroMemory(). Optimising compilers do strange things like that.

This topic is closed to new replies.

Advertisement