Unhandled exceptions when creating Device.

Started by
12 comments, last by tragic 9 years ago

So I just recently switched to Visual studio 2013 community edition and I am having trouble creating the device. Code that would work perfectly under VS2012 seems to be very broken in VS2013. On the mp_Device, mp_ImmediateContext and m_FeatureLevel I am having unhandled exceptions of 0xCDCDCDCD. I have included all of the appropriate headers and libs, I also have a GTX 980 so my system is more than capable of DirectX11.


bool D3DRenderSystem::InitializeDevice()
{ 
	// Set the desired target feature levels.
	D3D_FEATURE_LEVEL featureLevels[] =
	{
		D3D_FEATURE_LEVEL_11_0,
		D3D_FEATURE_LEVEL_10_1,
		D3D_FEATURE_LEVEL_10_0,
		D3D_FEATURE_LEVEL_9_3
	};

	HRESULT result = S_OK;

	D3D_FEATURE_LEVEL featureLevel;
	// Create the D3D11 Device with a hardware driver as well as with desired feature levels. 
	// This also creates the Immediate Context and sets which feature level we are using.
	result = D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, 0, featureLevels, 3, D3D11_SDK_VERSION, &mp_Device, &featureLevel, &mp_ImmediateContext);
		if (FAILED(result))
			return false;

	return true; 
}

class D3DRenderSystem
{
public:
	D3DRenderSystem();
	~D3DRenderSystem();

	bool InitializeDevice();
	bool InitializeSwapChain();

	void Shutdown();
	
	void Draw();

	ID3D11Device* GetDevice();

private:
	ID3D11Device* mp_Device;
	ID3D11DeviceContext* mp_ImmediateContext;
	ID3D11DepthStencilState* mp_DepthStencilState;
	ID3D11DepthStencilView* mp_DepthStencilView;
	D3D_FEATURE_LEVEL m_FeatureLevel;
	WindowClass* mh_OutputWindow;
		
};
Advertisement
The value 0xcdcdcdcd represents a previously freed block and is set this way by the visual studio leak checking malloc()/new. You might want to check through your code for allocation errors, it may be that your previous code has issues that 2012 did not detect but 2013 can...
Can you check what the hresult says after the failed creation?

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

I think he's saying that creation succeeds but the pointers returned afterwards are bogus, correct?
My money is on uninitialised variables, or some other generic C++ bug. It's almost certainly unrelated to D3D.

Post some more code from that class, like it's constructor / how it's initialized.

There’s also a rule of 3 violation in that class BTW.

Can you check what the hresult says after the failed creation?

Its crashing before the D3D11CreateDevice() returns a value. So the HRESULT would be S_OK still.

I think he's saying that creation succeeds but the pointers returned afterwards are bogus, correct?

Sadly it doesn't even get that far. It crashes while its mid D3D11CreateDevice().

My money is on uninitialised variables, or some other generic C++ bug. It's almost certainly unrelated to D3D.

Post some more code from that class, like it's constructor / how it's initialized.

There’s also a rule of 3 violation in that class BTW.


D3DRenderSystem::D3DRenderSystem() : mp_Device(nullptr), mp_ImmediateContext(nullptr), 
mp_DepthStencilState(nullptr), mp_DepthStencilView(nullptr),
	m_FeatureLevel(D3D_FEATURE_LEVEL_11_0), mp_OutputWindow(nullptr)
	{
	}


	D3DRenderSystem::~D3DRenderSystem()
	{
	}


	void D3DRenderSystem::Shutdown()
	{
		// Self explanatory.
		SafeReleaseCOM(mp_Device);
		SafeReleaseCOM(mp_ImmediateContext);
	}


	void D3DRenderSystem::Draw()
	{
	
	}
	
	
	ID3D11Device* D3DRenderSystem::GetDevice()
	{ 
		// Self explanatory.
		return mp_Device;
	}

Didn't know about that rule of 3. Ill implement that as soon as I get back from work.

What does the code that creates a D3DRenderSystem and calls InitializeDevice look like?

This may be off topic, but shouldn't you call shutdown from your destructor? That way, no matter what, your references will be released...

Also, any time you think you are having issues with API calls from D3D, make sure you create your device with the debug flags added. This will usually print a helpful diagnostic that will help you figure out what is going on.

What does the code that creates a D3DRenderSystem and calls InitializeDevice look like?


// Part of a larger function...
// mp_Render(nullptr) in constructor

// Initialize the rendering engine.
mp_Render = new D3DRenderSystem;
	if (!mp_Render)
	{
		return false;
	}
mp_Render->InitializeDevice();

So I just tried something and it works...kind of.

I put the device, feature level, and device context pointers inside the function and it does not crash...However this does not help since Im restricted to function scope.


bool D3DRenderSystem::InitializeDevice()
{ 
	// Set the desired target feature levels.
	D3D_FEATURE_LEVEL featureLevels[] =
	{
		D3D_FEATURE_LEVEL_11_0,
		D3D_FEATURE_LEVEL_10_1,
		D3D_FEATURE_LEVEL_10_0,
		D3D_FEATURE_LEVEL_9_3
	};

	HRESULT result = E_FAIL;

// Create the D3D11 Device with a hardware driver as well as with desired feature levels. 
// This also creates the Immediate Context and sets which feature level we are using.
	ID3D11Device* a = nullptr;
	ID3D11DeviceContext* b = nullptr;
	D3D_FEATURE_LEVEL c = D3D_FEATURE_LEVEL_11_0;

	result = D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, 2, featureLevels, 3, D3D11_SDK_VERSION, &a, &c, &b);
	if (FAILED(result))
		return false;

	return true; 
}

Don't know if this helps. http://i.imgur.com/epIEEmw.png

It looks like the program can't access the member variables of the class.

This topic is closed to new replies.

Advertisement