• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
alexisgreene

Crash on exit

17 posts in this topic

I recently had to rewrite my entire game engine and today I just got to rewriting the renderer. I wrote the code to initiate and shutdown D3D11 and decided to test it before continuing. It worked perfectly and closed without a crash. I added some code just to turn the window green to make sure that the renderer was working. It worked but now an exception is raised when I close the application.

This is the exact error that pops up in the debugger:
rdk_client_DEBUG.exe has triggered a breakpoint.

That's all it says, nothing else.


Stepping through with the debugger, it is triggered when IDXGISwapChain::Release() is called. The object itself is in fact valid. I commented out the code to turn the screen green, ran it, and the application closed without any issues.


Here is my shutdown code:

	if(m_pImmediateContext != nullptr)
		m_pImmediateContext->ClearState();

	ReleaseSamplerStates();
	ReleaseConstantBuffers();
	ReleaseRasterizerStates();
	ReleasePixelShaders();
	ReleaseVertexShaders();

	if(m_pDepthStencilTexture != nullptr)
	{
		m_pDepthStencilTexture->Release();
		m_pDepthStencilTexture = nullptr;
	}
	if(m_pDepthStencilView != nullptr)
	{
		m_pDepthStencilView->Release();
		m_pDepthStencilView = nullptr;
	}
	if(m_pRenderTargetView != nullptr)
	{
		m_pRenderTargetView->Release();
		m_pRenderTargetView = nullptr;
	}
	if(m_pSwapChain != nullptr)
	{
		// You may not release a swap chain in full-screen mode because doing so may create
		// thread contention (which will cause DXGI to raise a non-continuable exception).
		// Before releasing a swap chain, first switch to windowed mode
		// (using IDXGISwapChain::SetFullscreenState( FALSE, NULL )) and then call IUnknown::Release.
		m_pSwapChain->SetFullscreenState(FALSE, NULL);

		//**********************************************************
		// THIS IS WHAT CAUSES THE CRASH
		m_pSwapChain->Release();
		//**********************************************************
		m_pSwapChain = nullptr;
	}
	if(m_pImmediateContext != nullptr)
	{
		m_pImmediateContext->Release();
		m_pImmediateContext = nullptr;
	}
	if(m_pDevice != nullptr)
	{
		m_pDevice->Release();
		m_pDevice = nullptr;
	}
	if(m_pAdapter != nullptr)
	{
		m_pAdapter->Release();
		m_pAdapter = nullptr;
	}
	if(m_pFactory != nullptr)
	{
		m_pFactory->Release();
		m_pFactory = nullptr;
	}

 

And here is the code that causes it to crash on exit:

void rdk::render::CRenderD3D::Update(void)
{
    float color[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
	m_pImmediateContext->ClearRenderTargetView(m_pRenderTargetView, color);
	m_pImmediateContext->ClearDepthStencilView(m_pDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);
	m_pSwapChain->Present(0, 0);
}

 

I am only running in windowed mode right now by the way. Commenting out the call to m_pSwapChain->Present() will allow the application to once again close without a crash.

Why?

[EDIT] If I continue (instead of break) when this happens, the application will continue to exit without any further issues. This is in the debugger of course.

Edited by Deortuka
0

Share this post


Link to post
Share on other sites

Nothing from D3D debug layer. The only message I get in the output is:

HEAP[rdk_client_DEBUG.exe]: HEAP: Free Heap block 393ae90 modified at 393af48 after it was freed
rdk_client_DEBUG.exe has triggered a breakpoint.

 

This is confusing me quite a bit. How can making a call to IDXGISwapChain::Present() cause this to happen when I release it? Commenting out that Present() call allows the application to close without crashing.

0

Share this post


Link to post
Share on other sites

Hi!

 

It looks like you are calling released interfaces (Direct3D and Context).

Maybe you would disable the rendering code while exiting the app.

0

Share this post


Link to post
Share on other sites

Are you calling the shutdown inside a WindowProc handler? That can lead to all kind of weird bugs. Try to set a flag on your close message and handle the D3D shutdown in your message pump.

0

Share this post


Link to post
Share on other sites

I do not call it from the WindowProc. I specifically call a function that shuts down the renderer and other sub-systems from WinMain(), after the message loop has been canceled (which happens once a WM_QUIT message has been called)

	MSG msg;
	memset(&msg, 0, sizeof(msg));

	// this must be called by the main application thread
	rdk::engine_client::IEngineClient* pEngine = rdk::engine_client::GetEngineClientInterface();
	if(!pEngine->Initiate())
		return 0;

	bool bContinue = true;
	while(bContinue)
	{
		while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if(msg.message == WM_QUIT)
				bContinue = false;
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		pEngine->Update();
	}

	pEngine->ShutDown();
	return static_cast<int>(msg.wParam);

 

The only other code that could possibly be relevant is my start up code. I am in the process of rewriting my engine and stopped to take care of this bug before I finish writing the full renderer. My renderer is literally just start up and shut down code right now. Here is the code I use to start it up (hopefully one of you can catch something that I may be over looking):

	if(!DirectX::XMVerifyCPUSupport())
	{
		if(Params.pErrorLog != nullptr)
			Params.pErrorLog->Print(L"[rdk::render::CRenderD3D::Initiate] DirectX::XMVerifyCPUSupport() failed\n");
		return false;
	};

	if((m_pErrorLog != nullptr) ||
	   (m_pGenericLog != nullptr) ||
	   (m_pWindow != nullptr))
	{
		if(Params.pErrorLog != nullptr)
			Params.pErrorLog->Print(L"[rdk::render::CRenderD3D::Initiate] already initiated\n");
		return false;
	}

	m_pErrorLog = Params.pErrorLog;
	m_pGenericLog = Params.pGenericLog;
	m_pWindow = Params.pWindow;

	assert(m_pErrorLog != nullptr);
	assert(m_pGenericLog != nullptr);
	assert(m_pWindow != nullptr);

	{
		std::wostringstream stream(L"Direct3D ");
		stream << D3D11_MAJOR_VERSION << "." << D3D11_MINOR_VERSION << " (SDK version " << D3D11_SDK_VERSION << ")\n";
		m_pGenericLog->Print(stream.str());
	}

	HRESULT hr;
	hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)(&m_pFactory));
	if(FAILED(hr))
	{
		std::wstring str;
		LastDXError(hr, str);
		m_pErrorLog->Print(std::wstring(L"[rdk::render::CRenderD3D::Initiate::CreateDXGIFactory] ") + str + L"\n");
		ShutDown();
		return false;
	}

	hr = m_pFactory->EnumAdapters(0, &m_pAdapter);
	if(hr == DXGI_ERROR_NOT_FOUND)
	{
		std::wstring str;
		LastDXError(hr, str);
		m_pErrorLog->Print(std::wstring(L"[rdk::render::CRenderD3D::Initiate::m_pFactory->EnumAdapters] ") + str + L"\n");
		ShutDown();
		return false;
	}

	DXGI_ADAPTER_DESC Desc;
	hr = m_pAdapter->GetDesc(&Desc);
	if(FAILED(hr))
	{
		std::wstring str;
		LastDXError(hr, str);
		m_pErrorLog->Print(std::wstring(L"[rdk::render::CRenderD3D::Initiate::m_pAdapter->GetDesc] ") + str + L"\n");
		ShutDown();
		return false;
	}

	{
		std::wostringstream stream;
		stream << Desc.Description;
		stream << "\n Dedicated video memory: " << (static_cast<float>(Desc.DedicatedVideoMemory) / (1024 * 1024));
		stream << "\n Dedicated system memory: " << (static_cast<float>(Desc.DedicatedSystemMemory) / (1024 * 1024));
		stream << "\n Shared system memory: " << (static_cast<float>(Desc.SharedSystemMemory) / (1024 * 1024)) << L"\n";
		m_pGenericLog->Print(stream.str());
	}

	D3D_FEATURE_LEVEL featurelevels[] =
	{
		D3D_FEATURE_LEVEL_11_0,
		D3D_FEATURE_LEVEL_10_1,
		D3D_FEATURE_LEVEL_10_0,
	};

	D3D_FEATURE_LEVEL featurelevelcreated;
	UINT flags = 0;
#ifdef _DEBUG
	flags |= D3D11_CREATE_DEVICE_DEBUG;
	if(m_pGenericLog != nullptr)
		m_pGenericLog->Print(L"D3D11_CREATE_DEVICE_DEBUG\n");
#endif

	long	lWindowHeight = 0;
	long	lWindowWidth = 0;
	if(!m_pWindow->GetClientSize(lWindowHeight, lWindowWidth))
	{
		m_pErrorLog->Print(L"[rdk::render::CRenderD3D::Initiate] m_pWindow->GetClientSize() failed\n");
		ShutDown();
		return false;
	}

	DXGI_SWAP_CHAIN_DESC scd;
	memset(&scd, 0, sizeof(DXGI_SWAP_CHAIN_DESC));
	scd.BufferCount							= 1;
	scd.BufferDesc.Width					= lWindowWidth;
	scd.BufferDesc.Height					= lWindowHeight;
	scd.BufferDesc.Format					= DXGI_FORMAT_R8G8B8A8_UNORM;
	scd.BufferDesc.RefreshRate.Numerator	= 60;
	scd.BufferDesc.RefreshRate.Denominator	= 1;
	scd.BufferUsage							= DXGI_USAGE_RENDER_TARGET_OUTPUT;
	scd.OutputWindow						= m_pWindow->GetHWND();
	scd.SampleDesc.Count					= 1;
	scd.SampleDesc.Quality					= 0;
	scd.Windowed							= Params.bWindowed;

	hr = D3D11CreateDeviceAndSwapChain(m_pAdapter,
									   D3D_DRIVER_TYPE_UNKNOWN,
									   NULL,
									   flags,
									   featurelevels,
									   sizeof(featurelevels) / sizeof(featurelevels[0]),
									   D3D11_SDK_VERSION,
									   &scd,
									   &m_pSwapChain,
									   &m_pDevice,
									   &featurelevelcreated,
									   &m_pImmediateContext);
	if(FAILED(hr))
	{
		std::wstring str;
		LastDXError(hr, str);
		m_pErrorLog->Print(std::wstring(L"[rdk::render::CRenderD3D::Initiate::D3D11CreateDeviceAndSwapChain] ") + str + L"\n");
		ShutDown();
		return false;
	}

	// check which version was created
	switch(featurelevelcreated)
	{
	case D3D_FEATURE_LEVEL_11_0:
		m_pGenericLog->Print(L"D3D_FEATURE_LEVEL_11_0\n");
		break;
	case D3D_FEATURE_LEVEL_10_1:
		m_pGenericLog->Print(L"D3D_FEATURE_LEVEL_10_1\n");
		break;
	case D3D_FEATURE_LEVEL_10_0:
		m_pGenericLog->Print(L"D3D_FEATURE_LEVEL_10_0\n");
		break;
	default:	// unsupported version created
		m_pErrorLog->Print(L"[rdk::render::CRenderD3D::Initiate] failed to create a supported freature level\n");
		return false;
	}

	// create the back buffer
	ID3D11Texture2D *pBuffer = nullptr;
	hr = m_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&pBuffer));
	if(FAILED(hr))
	{
		std::wstring str;
		LastDXError(hr, str);
		m_pErrorLog->Print(std::wstring(L"[rdk::render::CRenderD3D::Initiate::m_pSwapChain->GetBuffer] ") + str + L"\n");
		ShutDown();
		return false;
	}
	hr = m_pDevice->CreateRenderTargetView(pBuffer, NULL, &m_pRenderTargetView);
	pBuffer->Release();
	if(FAILED(hr))
	{
		std::wstring str;
		LastDXError(hr, str);
		m_pErrorLog->Print(std::wstring(L"[rdk::render::CRenderD3D::Initiate::m_pDevice->CreateRenderTargetView] ") + str + L"\n");
		ShutDown();
		return false;
	}

	// create the depth stencil texture
	D3D11_TEXTURE2D_DESC td;
	memset(&td, 0, sizeof(td));
	td.Width				= lWindowWidth;
	td.Height				= lWindowHeight;
	td.MipLevels			= 1;
	td.ArraySize			= 1;
	td.Format				= DXGI_FORMAT_D24_UNORM_S8_UINT;
	td.SampleDesc.Count		= 1;
	td.SampleDesc.Quality	= 0;
	td.Usage				= D3D11_USAGE_DEFAULT;
	td.BindFlags			= D3D11_BIND_DEPTH_STENCIL;
	td.CPUAccessFlags		= 0;
	td.MiscFlags			= 0;

	hr = m_pDevice->CreateTexture2D(&td, NULL, &m_pDepthStencilTexture);
	if(FAILED(hr))
	{
		std::wstring str;
		LastDXError(hr, str);
		m_pErrorLog->Print(std::wstring(L"[rdk::render::CRenderD3D::Initiate::m_pDevice->CreateTexture2D] ") + str + L"\n");
		ShutDown();
		return false;
	}

	// create the depth stencil view
	D3D11_DEPTH_STENCIL_VIEW_DESC dsvd;
	memset(&dsvd, 0, sizeof(dsvd));
	dsvd.Format				= td.Format;
	dsvd.ViewDimension		= D3D11_DSV_DIMENSION_TEXTURE2D;
	dsvd.Texture2D.MipSlice	= 0;
	hr = m_pDevice->CreateDepthStencilView(m_pDepthStencilTexture, &dsvd, &m_pDepthStencilView);
	if(FAILED(hr))
	{
		std::wstring str;
		LastDXError(hr, str);
		m_pErrorLog->Print(std::wstring(L"[rdk::render::CRenderD3D::Initiate::m_pDevice->CreateDepthStencilView] ") + str + L"\n");
		ShutDown();
		return false;
	}
	m_pImmediateContext->OMSetRenderTargets(1, &m_pRenderTargetView, m_pDepthStencilView);

	// set the viewport
    D3D11_VIEWPORT vp;
    vp.Width	= static_cast<float>(lWindowWidth);
    vp.Height	= static_cast<float>(lWindowHeight);
    vp.MinDepth	= D3D11_MIN_DEPTH; // 0.0f;
    vp.MaxDepth	= D3D11_MAX_DEPTH; // 1.0f;
    vp.TopLeftX	= 0;
    vp.TopLeftY	= 0;
    m_pImmediateContext->RSSetViewports(1, &vp);

	// create rasterize states
	if(!CreateRasterizerStates())
	{
		m_pErrorLog->Print(L"[rdk::render::CRenderD3D::Initiate] CreateRasterizerStates() failed\n");
		ShutDown();
		return false;
	}
	m_pImmediateContext->RSSetState(m_RasterizerStates[DefaultRasterizerState]);

	// create the constant buffers
	if(!CreateConstantBuffers())
	{
		m_pErrorLog->Print(L"[rdk::render::CRenderD3D::Initiate] CreateConstantBuffers() failed\n");
		ShutDown();
		return false;
	}

	// create all sampler states
	if(!CreateSamplerStates())
	{
		m_pErrorLog->Print(L"[rdk::render::CRender::Initiate] CreateSamplerStates() failed\n");
		ShutDown();
		return false;
	}

	// load vertex shaders
	if(!LoadVertexShaders())
	{
		m_pErrorLog->Print(L"[rdk::render::CRender::Initiate] LoadVertexShaders() failed\n");
		ShutDown();
		return false;
	}

	// load pixel shaders
	if(!LoadPixelShaders())
	{
		m_pErrorLog->Print(L"[rdk::render::CRender::Initiate] LoadPixelShaders() failed\n");
		ShutDown();
		return false;
	}

	// set the default world transformation matrix
	SetWorldMatrix(DirectX::XMMatrixIdentity());

	// attach window callbacks
	if(!m_pWindow->AddCallback(WM_SIZE, Size))
	{
		m_pErrorLog->Print(L"[rdk::render::CRenderD3D::Initiate] Window.AddCallback(WM_SIZE) failed\n");
		ShutDown();
		return false;
	}

	return true;
0

Share this post


Link to post
Share on other sites
I am not sure if this may or may not be related, but the same thing happens when I play PlanetSide 2 (which is a UDK game I believe). The game runs fine but crashes on exit. There are many other people who complain about this issue in the forums for that game's website. Maybe I have the same problem that the developer's of that game have? Maybe this is an NVIDIA driver bug?

http://forums.station.sony.com/ps2/index.php?threads/planetside-2-crash-when-exit-game.48970/

[EDIT]
In order to test my NVIDIA driver bug theory, I did a fresh compile and ran it through the debugger. It crashed on exit. I made a copy of the binaries, one copy set to run on the default Intel graphics card and the other copy set to run on the NVIDIA graphics card. I ran both copies outside the debugger and both closed without a crash.

It seems that it only crashes on exit when running from the debugger. Maybe this is a bug with the VS2012 debugger? Edited by Deortuka
0

Share this post


Link to post
Share on other sites

You are a genius! I cant believe I stared at that code and did not notice that. I will change that, test it out, and let you know the results.

0

Share this post


Link to post
Share on other sites

I fixed the main loop but the problem still persists. I have spent many hours trying to locate the cause of this strange bug with no luck at all.

0

Share this post


Link to post
Share on other sites

A few things you can try:

 

- use the newer DXGI components, e.g.: IDXGIFactory1 and IDXGIAdapter1 instead of IDXGIFactory and IDXGIAdapter

- don't manually create the DXGI objects, but retrieve/query them from a D3D device (using the default adapter):

 

 

D3DDevice->QueryInterface(__uuidof(IDXGIDevice1), (void **)&DXGIDevice);
DXGIDevice->GetParent(__uuidof(IDXGIAdapter1), (void **)&DXGIAdapter);
DXGIAdapter->GetParent(__uuidof(IDXGIFactory1), (void **)&DXGIFactory);
0

Share this post


Link to post
Share on other sites

maybe m_pRenderTargetView and swap chain are the same before the shutdown.

I stepped through the shut down code to test this theory and now the crash occurs when I call m_pDevice->Release(). The only code change I have made is the fix to the message loop that iedoc pointed out to me. No pointers had the same value during shut down as well.

 

I am going to rewrite my start up code in order to accommodate the changes suggested by eppo. I will post my results once I have time to test those changes out.

0

Share this post


Link to post
Share on other sites
The application will crash if you try to release the device before releasing all the device's interface objects. Check that you release everything you initialized and set them all to null
0

Share this post


Link to post
Share on other sites

After hours upon hours of attempting to debug this with no success, I discovered that the exact same breakpoint is triggered when I resize my window. I decided to focus less on Direct 3D (because I am 99% sure that my D3D code is close to correct) and more on only message that the debugger output is giving me:

HEAP[rdk_client_DEBUG.exe]: HEAP: Free Heap block 393ae90 modified at 393af48 after it was freed
rdk_client_DEBUG.exe has triggered a breakpoint.
This breakpoint, according to google, is triggered a little while after the actual illegal access has occurred. This explains why the crash seems to occur in different places after I make changes to the code. One recommendation I found for tracking down the true culprit is to "sprinkle" this assert throughout my code:
assert(_CrtCheckMemory());
The leading "_Crt" made me realize that I may be improperly using an STL container somewhere in my code. I will continue to search for the cause of this annoying bug and post the results. Thanks for the help so far.
0

Share this post


Link to post
Share on other sites

i used neither stl  nor some other third-party code,  Actually i simplified my code as below:

#include <Windows.h>
#include <d3d11.h>
#pragma comment(lib,"d3d11.lib")
LRESULT CALLBACK Hur_WinProc11(HWND hWnd, unsigned int msg, unsigned int wParam, long  lParam)
{
	switch(msg)
	{
	case WM_DESTROY:
		{  
			PostQuitMessage( WM_QUIT );
			return 0;
		}
	}
	return DefWindowProc(hWnd, msg, wParam, lParam );
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE , LPSTR , int) 
{
	IDXGISwapChain*          m_SwapChain;
	ID3D11Device*            m_D11Device;
	ID3D11DeviceContext*     m_DeviceContext;
	ID3D11RenderTargetView*  m_RenderTargetView;
	HRESULT result;
	WNDCLASSEX wcex;
	wcex.cbSize=					sizeof(WNDCLASSEX);
	wcex.style=						(CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS);
	wcex.cbClsExtra=				0;
	wcex.cbWndExtra=			0;
	wcex.hInstance=				GetModuleHandle( NULL );
	wcex.hIcon=						NULL;
	wcex.hCursor=					LoadCursor(NULL,IDC_ARROW);
	wcex.hbrBackground=   (HBRUSH)GetStockObject(WHITE_BRUSH);
	wcex.lpszMenuName=   NULL;
	wcex.hIconSm=				NULL;
	wcex.lpfnWndProc =		Hur_WinProc11;
	wcex.lpszClassName=    L"hhh";
	RegisterClassEx (&wcex);
	HWND hwnd = CreateWindow(wcex.lpszClassName, L"ggg", WS_OVERLAPPEDWINDOW, 40, 80, 60+16, 70+36, NULL, NULL, wcex.hInstance, NULL);



	D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0;
	DXGI_SWAP_CHAIN_DESC swapChainDesc;
	ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));

	swapChainDesc.BufferCount = 1;
	swapChainDesc.BufferDesc.Width  = 60+16;
	swapChainDesc.BufferDesc.Height = 70+36;
	swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	swapChainDesc.BufferDesc.RefreshRate.Numerator = 1;
	swapChainDesc.BufferDesc.RefreshRate.Denominator = 60;
	swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
	swapChainDesc.OutputWindow = hwnd;
	swapChainDesc.SampleDesc.Count = 1;
	swapChainDesc.SampleDesc.Quality = 0;
	swapChainDesc.Windowed = true;

	result = D3D11CreateDeviceAndSwapChain(NULL, 
		D3D_DRIVER_TYPE_HARDWARE, 
		NULL, 
		0, 
		&featureLevel, 
		1, 
		D3D11_SDK_VERSION, 
		&swapChainDesc, 
		&m_SwapChain, 
		&m_D11Device, 
		NULL, 
		&m_DeviceContext);
	if(FAILED(result))
	{
		return 0;
	}

	ID3D11Texture2D* backBufferPtr;
	result = m_SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&backBufferPtr));
	result = m_D11Device->CreateRenderTargetView(backBufferPtr, NULL, &m_RenderTargetView);
	backBufferPtr->Release();


 	m_DeviceContext->OMSetRenderTargets(1, &m_RenderTargetView, 0);
 	m_SwapChain->Present(0, 0); 


	if(m_SwapChain) m_SwapChain->Release();
	if(m_DeviceContext) m_DeviceContext->Release();
	if(m_RenderTargetView) m_RenderTargetView->Release(); 
	if(m_D11Device) m_D11Device->Release();


	return 1;
}                

 

The code seems correct, but this annoying bug still occured? What it really confused me is, no matter what the release() order is, the brake is always triggerd on the last release call. 

0

Share this post


Link to post
Share on other sites

Well, it turns out that STL wasn't the cause. Nor did that assert yield any different results. I am really beginning to believe that this is a bug with the VS2012 debugger because when I run the same debug executable from the folder (and not through the debugger) this breakpoint is never triggered. Not when I resize and not when I exit the application.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0