Program crashes.

Compiling gives no errors. When running in debug it crashes and then points me to the file memset.asm with this: "rep stosd" highlighted.

I've got a feeling it may be in this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
bool DirectX::InitializeD3D(HWND hwnd, int width, int height, bool fullscreen) { 
	
	ZeroMemory(&sd, sizeof(sd));

	sd.BufferCount = 1;
	sd.BufferDesc.Width = width;
	sd.BufferDesc.Height = height;
	sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	sd.BufferDesc.RefreshRate.Numerator = 60;
	sd.BufferDesc.RefreshRate.Denominator = 1;
	sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	sd.OutputWindow = hwnd;
	sd.SampleDesc.Count = 1;
	sd.SampleDesc.Quality = 0;
	sd.Windowed = (!fullscreen) ? false : true;
Go up the call stack in your debugger and see what line is causing the problem.
Zhuge wrote:
Go up the call stack in your debugger and see what line is causing the problem.


You're write. If you're using Visual Studio or any good IDE, you can set breakpoints and step through the code to see which lines draws the error.
this line: ZeroMemory(&sd, sizeof(sd)); is highlighted yellow when it crashes with a breakpoint.
http://puu.sh/5p6c8.png

callstack: http://puu.sh/5p6hx.png
What is sd? Is it initialized to a real value?
private:
DXGI_SWAP_CHAIN_DESC sd;

That's sd, it's not set to any value apart from the above code.
What is a DXGI_SWAP_CHAIN_DESC, and where is sd defined? Is it a member of the DirectX class?
it is a member of the directX class and see here: http://msdn.microsoft.com/en-us/library/windows/desktop/bb173075(v=vs.85).aspx
I see no reason why memsetting a DX struct would crash.

Only thing I can think of is that your 'this' pointer is bad.

Open a watch window and look at this. Is it something wonky like 0xcdcdcdcd?


EDIT:

To elaborate further... your 'this' pointer can be bad if you do not call the InitializeD3D function with a valid object. So if you're doing something like this:

1
2
DirectX* ptr;  // <- uninitialized pointer
ptr->InitializeD3D( /*... */ ); // <- your 'this' pointer will be bad. 
Last edited on
Ah I've done what you've said in your edit. What should I do?
Last edited on
Also this might help in solving the issue:

http://puu.sh/5pie0.png
thefatshizms:

Why are you making it a pointer? Why not make it an object?

1
2
3
4
5
6
7
// bad
DirectX* ptr;
ptr->InitializeD3D( /* ... */ );

// better
DirectX obj;
obj.InitializeD3D( /* ... */ );


If you really need it to be dynamically allocated, you can do that:

1
2
std::unique_ptr<DirectX> ptr( new DirectX );
ptr->InitializeD3D( /* ... */ );


But in general... don't use pointers unless you have to.
Still crashing :/ this time it's highlighting the buffercount line. I fixed it highlighting the ZeroMemory by making the variable sd local to the scope.
I fixed it highlighting the ZeroMemory by making the variable sd local to the scope


That does not really fix the problem, it just dodges it. The problem is your 'this' pointer is bad because you're calling this function with a bad pointer. That is what you need to fix.

The bug is not in the InitializeD3D function. It's before it. Post the code that's calling this function.
Last edited on
1
2
3
4
5
6
DirectX d3d;
	

	if(!d3d.InitializeD3D(hwnd, 600, 300, false)) {
		return 0;
	}

That's within the WinMain function right after I show and update the window.
Okay so you fixed that. That's good. So it's not the this pointer anymore.

So is the crash message now different from what it was before? What is the message now?
It seems to now highlight featurelevels in the console

- featurelevels 0x003cf934 {-858993460, -858993460, -858993460, -858993460, -858993460, -858993460} D3D_FEATURE_LEVEL[6]

1
2
3
4
5
6
7
8
9
D3D_FEATURE_LEVEL featurelevels[] = 
	{
		D3D_FEATURE_LEVEL_11_0,
		D3D_FEATURE_LEVEL_10_1,
		D3D_FEATURE_LEVEL_10_0,
		D3D_FEATURE_LEVEL_9_3,
		D3D_FEATURE_LEVEL_9_2,
		D3D_FEATURE_LEVEL_9_1,
	};
I mean... the program is crashing, right? When it crashes you get a popup box with an error message. What is the error message?
can u post whole initialization code? (I mean if it's not to big...)
It seems I fixed the code some posts up but then forgot to remove the breakpoints. Works now, thanks :)
Topic archived. No new replies allowed.