DX11 - Preparing for Release Mode

Started by
19 comments, last by Migi0027 10 years, 9 months ago

That flag was removed when porting to the new pc.

Do you have any idea how you can get the inside information on what wen't wrong? If possible.

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Advertisement

If useful, here's how I initialize Directx:


#pragma region NativeDirectx
	HRESULT result;
	IDXGIFactory* factory;
	IDXGIAdapter* adapter;
	IDXGIOutput* adapterOutput;
	unsigned int numModes, i, numerator, denominator, stringLength;
	DXGI_MODE_DESC* displayModeList;
	DXGI_ADAPTER_DESC adapterDesc;
	int error;
	DXGI_SWAP_CHAIN_DESC swapChainDesc;
	D3D_FEATURE_LEVEL featureLevel;
	ID3D11Texture2D* backBufferPtr;
	D3D11_TEXTURE2D_DESC depthBufferDesc;
	D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
	D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc;
	D3D11_RASTERIZER_DESC rasterDesc;
	D3D11_VIEWPORT viewport;
	float fieldOfView, screenAspect;


	// Store the vsync setting.
	bool m_vsync_enabled = false;

	// Create a DirectX graphics interface factory.
	result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
	if(FAILED(result))
	{
		CE_ERROR("Error in creating CESDK", "FATAL ERROR");
	}

	// Use the factory to create an adapter for the primary graphics interface (video card).
	result = factory->EnumAdapters(0, &adapter);
	if(FAILED(result))
	{
		CE_ERROR("Error in creating CESDK", "FATAL ERROR");
	}

	// Enumerate the primary adapter output (monitor).
	result = adapter->EnumOutputs(0, &adapterOutput);
	if(FAILED(result))
	{
		CE_ERROR("Error in creating CESDK", "FATAL ERROR");
	}

	// Get the number of modes that fit the DXGI_FORMAT_R8G8B8A8_UNORM display format for the adapter output (monitor).
	result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, NULL);
	if(FAILED(result))
	{
		CE_ERROR("Error in creating CESDK", "FATAL ERROR");
	}

	// Create a list to hold all the possible display modes for this monitor/video card combination.
	displayModeList = new DXGI_MODE_DESC[numModes];
	if(!displayModeList)
	{
		CE_ERROR("Error in creating CESDK", "FATAL ERROR");
	}

	// Now fill the display mode list structures.
	result = adapterOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numModes, displayModeList);
	if(FAILED(result))
	{
		CE_ERROR("Error in creating CESDK", "FATAL ERROR");
	}

	// Now go through all the display modes and find the one that matches the screen width and height.
	// When a match is found store the numerator and denominator of the refresh rate for that monitor.
	for(i=0; i<numModes; i++)
	{
		if(displayModeList[i].Width == (unsigned int)sw)
		{
			if(displayModeList[i].Height == (unsigned int)sh)
			{
				numerator = displayModeList[i].RefreshRate.Numerator;
				denominator = displayModeList[i].RefreshRate.Denominator;
			}
		}
	}

	// Get the adapter (video card) description.
	result = adapter->GetDesc(&adapterDesc);
	if(FAILED(result))
	{
		CE_ERROR("Error in creating CESDK", "FATAL ERROR");
	}

	// Store the dedicated video card memory in megabytes.
	m_videoCardMemory = (int)(adapterDesc.DedicatedVideoMemory / 1024 / 1024);

	// Convert the name of the video card to a character array and store it.
	error = wcstombs_s(&stringLength, m_videoCardDescription, 128, adapterDesc.Description, 128);
	if(error != 0)
	{
		CE_ERROR("Error in creating CESDK", "FATAL ERROR");
	}

	// Release the display mode list.
	delete [] displayModeList;
	displayModeList = 0;

	// Release the adapter output.
	adapterOutput->Release();
	adapterOutput = 0;

	// Release the adapter.
	adapter->Release();
	adapter = 0;

	// Release the factory.
	factory->Release();
	factory = 0;

	// Initialize the swap chain description.
	ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));

	// Set to a single back buffer.
	swapChainDesc.BufferCount = 1;

	// Set the width and height of the back buffer.
	swapChainDesc.BufferDesc.Width = sw;
	swapChainDesc.BufferDesc.Height = sh;

	// Set regular 32-bit surface for the back buffer.
	swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;

	// Set the refresh rate of the back buffer.
	if(m_vsync_enabled)
	{
		swapChainDesc.BufferDesc.RefreshRate.Numerator = numerator;
		swapChainDesc.BufferDesc.RefreshRate.Denominator = denominator;
	}
	else
	{
		swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
		swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
	}

	// Set the usage of the back buffer.
	swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;

	// Set the handle for the window to render to.
	swapChainDesc.OutputWindow = hWnd;

	// Turn multi sampling off.
	swapChainDesc.SampleDesc.Count = 1;
	swapChainDesc.SampleDesc.Quality = 0;

	// Set to full screen or windowed mode.
	if(windowed)
	{
		swapChainDesc.Windowed = true;
	}
	else
	{
		swapChainDesc.Windowed = false;
	}

	// Set the scan line ordering and scaling to unspecified.
	swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
	swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;

	// Discard the back buffer contents after presenting.
	swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;

	// Don't set the advanced flags.
	swapChainDesc.Flags = 0;

	// Set the feature level to DirectX 11.
	featureLevel = D3D_FEATURE_LEVEL_11_0;

	// Create the swap chain, Direct3D device, and Direct3D device context.
	result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, &featureLevel, 1, 
		D3D11_SDK_VERSION, &swapChainDesc, &swapchain, &dev, NULL, &devcon);
	if(FAILED(result))
	{
		CE_ERROR("Error in creating CESDK", "FATAL ERROR");
	}

	ZeroMemory(&texd, sizeof(texd));

	texd.Width = sw;
	texd.Height = sh;
	texd.ArraySize = 1;
	texd.MipLevels = 1;
	texd.SampleDesc.Count = 1;	
	texd.SampleDesc.Quality = 0;
	texd.Format = DXGI_FORMAT_D32_FLOAT;
	texd.BindFlags = D3D11_BIND_DEPTH_STENCIL;

	ID3D11Texture2D *pDepthBuffer;
	dev->CreateTexture2D(&texd, NULL, &pDepthBuffer);

	ZeroMemory(&dsvd, sizeof(dsvd));

	dsvd.Format = DXGI_FORMAT_D32_FLOAT;
	dsvd.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;

	dev->CreateDepthStencilView(pDepthBuffer, &dsvd, &zbuffer);

	if (pDepthBuffer != nullptr)
		pDepthBuffer->Release();

	// get the address of the back buffer
	ID3D11Texture2D *pBackBuffer;
	swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer);

	// use the back buffer address to create the render target
	dev->CreateRenderTargetView(pBackBuffer, NULL, &backbuffer);

	if (pBackBuffer != nullptr)
		pBackBuffer->Release();

	// set the render target as the back buffer
	devcon->OMSetRenderTargets(1, &backbuffer, zbuffer);


	// Set the viewport
	ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));

	viewport.TopLeftX = 0;    // set the left to 0
	viewport.TopLeftY = 0;    // set the top to 0
	viewport.Width = sw;    // set the width to the window's width
	viewport.Height = sh;    // set the height to the window's height
	viewport.MinDepth = 0;    // the closest an object can be on the depth buffer is 0.0
	viewport.MaxDepth = 1;    // the farthest an object can be on the depth buffer is 1.0

	devcon->RSSetViewports(1, &viewport);
	#pragma endregion

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

A quick look at your code seems to have enough security checks to catch if there's anything wrong with the device creation and setup process. I'm afraid i have no more suggestions to your problem. sad.png

The worse bug that i can actually think of is if somewhere in your code is doing a buffer overflow and overwrites your graphics device context. I'm not sure if this can be detected with the use of _CrtSetDbgFlag() and _CrtDumpMemoryLeaks() but with those security checks that you have above i doubt you're doing this mistake somewhere in your code.

I hope someone here can help you out and i'm also eager to learn what exactly is the problem with your code and its fix.

Do you think using a copy pasted DX11 SDK folder could cause this problem?

(I didn't download the sdk again... too lazy... laugh.png )

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

I'm not sure... I don't exactly know the exact content of the SDK installer but i'm guessing besides the API it installs some additional DX runtimes in your systems folder as well. That may be a reason to have a crash like a wrong version of the runtime libraries? But then again it should cause an error message just before your app runs instead of having a weird crash.

Is the crash a BSOD?

No the crash is not a bsod, just the graphics driver crash.

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

It even fails when sending the shader: (Though, here it doesn't crash, but it sends an exception [ Access violation reading location 0xBAADF015. ] )

devcon->VSSetShader(pVS, 0, 0);

, and the shader is created and validated, no errors!

This is really wierd.

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Ok, just tweaking, looking and stuff.

And it finally ran! (... in debug mode happy.png )

But black...

So I ran PIX, and found out that the full screen quad was being rendered, with color. So looking over the code again, the stencils weren't being restored properly.

But I guess the next goal is to make it run in Release Mode, but for now, I'm just going to play around a bit.

Just one question: Can Directx 11 with c++ corrupt the system, or cause BSOD, even if the system is healthy?

Thanks for your help! wink.png

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Ok, just tweaking, looking and stuff.

And it finally ran! (... in debug mode happy.png )

But black...

So I ran PIX, and found out that the full screen quad was being rendered, with color. So looking over the code again, the stencils weren't being restored properly.

But I guess the next goal is to make it run in Release Mode, but for now, I'm just going to play around a bit.

Just one question: Can Directx 11 with c++ corrupt the system, or cause BSOD, even if the system is healthy?

Thanks for your help! wink.png

The code itself shouldn't cause BSOD or other "enjoyable" Windows hangs and crashes...

Any crashes/hangs/BSOD/nuclear disaster/celin dion song/zombie pandemic/etc. caused by a direct3d application are related with the quality of the video drivers only; with the introduction of WDDM (since Vista), most of problems appear as driver crashes with reset to desktop (or just with some seconds of hangs without the application crash if you are lucky)...

"Recursion is the first step towards madness." - "Skegg?ld, Skálm?ld, Skildir ro Klofnir!"
Direct3D 12 quick reference: https://github.com/alessiot89/D3D12QuickRef/

Ok, just tweaking, looking and stuff.

And it finally ran! (... in debug mode happy.png )

But black...

So I ran PIX, and found out that the full screen quad was being rendered, with color. So looking over the code again, the stencils weren't being restored properly.

But I guess the next goal is to make it run in Release Mode, but for now, I'm just going to play around a bit.

Just one question: Can Directx 11 with c++ corrupt the system, or cause BSOD, even if the system is healthy?

Thanks for your help! wink.png

The code itself shouldn't cause BSOD or other "enjoyable" Windows hangs and crashes...

Any crashes/hangs/BSOD/nuclear disaster/celin dion song/zombie pandemic/etc. caused by a direct3d application are related with the quality of the video drivers only; with the introduction of WDDM (since Vista), most of problems appear as driver crashes with reset to desktop (or just with some seconds of hangs without the application crash if you are lucky)...

Phew.. happy.png

Ok, thanks!

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

This topic is closed to new replies.

Advertisement