Jump to content

  • Log In with Google      Sign In   
  • Create Account


Crash on exit


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
17 replies to this topic

#1 Deortuka   Members   -  Reputation: 493

Like
0Likes
Like

Posted 19 January 2013 - 11:04 AM

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, 19 January 2013 - 11:11 AM.


Sponsor:

#2 eppo   Crossbones+   -  Reputation: 2406

Like
0Likes
Like

Posted 20 January 2013 - 08:52 AM

Does the D3D debug layer tell you anything?



#3 Deortuka   Members   -  Reputation: 493

Like
0Likes
Like

Posted 20 January 2013 - 10:40 AM

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.



#4 kubera   Members   -  Reputation: 906

Like
0Likes
Like

Posted 20 January 2013 - 12:17 PM

Hi!

 

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

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



#5 ankhd   Members   -  Reputation: 1243

Like
0Likes
Like

Posted 20 January 2013 - 07:29 PM

It's some where else in your code then

#6 Endurion   Crossbones+   -  Reputation: 3490

Like
0Likes
Like

Posted 20 January 2013 - 11:52 PM

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.


Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

#7 Deortuka   Members   -  Reputation: 493

Like
0Likes
Like

Posted 21 January 2013 - 12:37 AM

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;


#8 Deortuka   Members   -  Reputation: 493

Like
0Likes
Like

Posted 21 January 2013 - 12:47 AM

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, 21 January 2013 - 03:22 AM.


#9 iedoc   Members   -  Reputation: 934

Like
3Likes
Like

Posted 21 January 2013 - 06:45 PM

After you receive a quit message in your message loop, you dispatch it which starts closing your window THEN you try to update your engine one more time before exiting which calls the present method but there is probably no window to present to since the quit message was dispatched. Don't update your engine after you dispatch a quit message. Use an if statement, so if a quit message is received, quit the program, otherwise if bContinue is still true update the engine. This is a bug in your code, so sometimes it crashes and sometimes not. Probably depends on if your engine is fast enough to call present one more time before the window is closed, which is why it might work in a release build and not a debug build
Braynzar Soft - DirectX Lessons & Game Programming Resources!

#10 Deortuka   Members   -  Reputation: 493

Like
0Likes
Like

Posted 21 January 2013 - 10:36 PM

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.



#11 Deortuka   Members   -  Reputation: 493

Like
0Likes
Like

Posted 25 January 2013 - 09:06 AM

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.



#12 eppo   Crossbones+   -  Reputation: 2406

Like
0Likes
Like

Posted 25 January 2013 - 10:35 AM

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);


#13 he3117   Members   -  Reputation: 374

Like
0Likes
Like

Posted 26 January 2013 - 02:32 AM

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



#14 Deortuka   Members   -  Reputation: 493

Like
0Likes
Like

Posted 28 January 2013 - 11:52 AM

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.



#15 iedoc   Members   -  Reputation: 934

Like
0Likes
Like

Posted 28 January 2013 - 03:32 PM

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
Braynzar Soft - DirectX Lessons & Game Programming Resources!

#16 Deortuka   Members   -  Reputation: 493

Like
0Likes
Like

Posted 05 February 2013 - 04:20 PM

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.

#17 HolyOdin   Members   -  Reputation: 130

Like
0Likes
Like

Posted 06 February 2013 - 10:55 PM

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. 



#18 Deortuka   Members   -  Reputation: 493

Like
0Likes
Like

Posted 07 February 2013 - 09:09 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS