Ejemplo n.º 1
1
void gep::Renderer::destroy()
{
    m_pDummyTexture = nullptr;
    m_pDummyShader = nullptr;
    m_pDummyModel = nullptr;

    DELETE_AND_NULL(m_pFontBuffer);
    DELETE_AND_NULL(m_pLinesBuffer);
    DELETE_AND_NULL(m_pLines2DBuffer);

    GEP_RELEASE_AND_NULL(m_pRenderTargetView);
    GEP_RELEASE_AND_NULL(m_pDepthStencilView);
    GEP_RELEASE_AND_NULL(m_pSwapChain);
    if(m_pDeviceContext)
    {
        m_pDeviceContext->ClearState();
        m_pDeviceContext->Flush();
        m_pDeviceContext->Release();
        m_pDeviceContext = nullptr;
    }
    if(m_pd3dDevice) {
        m_pd3dDevice->Release();
        m_pd3dDevice = nullptr;
    }
    destroyWindow();


    const GUID DXGI_DEBUG_ALL2 = { 0xe48ae283, 0xda80, 0x490b, { 0x87, 0xe6,  0x43,  0xe9,  0xa9,  0xcf,  0xda,  0x8 } };

    delete m_pDebugRenderer; m_pDebugRenderer = nullptr;
#ifdef _DEBUG
    //ComLeakFinder::destroyInstance();
    auto handle = GetModuleHandle(L"dxgidebug.dll");
    if(handle != INVALID_HANDLE_VALUE)
    {
        auto fun = reinterpret_cast<decltype(&DXGIGetDebugInterface)>(GetProcAddress(handle, "DXGIGetDebugInterface"));
        if (fun) // TODO FIXME: "DXGIGetDebugInterface" not found on certain systems
        {
            IDXGIDebug* pDebug = nullptr;
            fun(__uuidof(IDXGIDebug), (void**)&pDebug);
            if (pDebug)
            {
                pDebug->ReportLiveObjects(DXGI_DEBUG_ALL2, DXGI_DEBUG_RLO_ALL);
            }
        }
    }
#endif
}
Ejemplo n.º 2
0
void DesktopApp::Run()
{
	// ------------- init Engine objects
	Assert(!Engine::instance().isInit());
	Engine::instance().initLowLevel();

	try
	{
		// ------------- call main class init()
		m_mainClass->init();
		m_frameDurationCounter.init();

		while (Engine::instance().isRunning() && !reinterpret_cast<const DesktopWindow*>(getWindow())->mustBeDestroyed()) // ------------ MAIN LOOP
		{
			// ------------ manage events

			this->manageEvents();

			if (!m_suspended)
			{
				// ------------- call main class update()

				bool needProcessAgain = m_mainClass->update();

				if (reinterpret_cast<const DesktopWindow*>(getWindow())->mustBeDestroyed() || !Engine::instance().isRunning()) break;

				Engine::instance().updateInternals();

				// ------------ call main class render()

				this->BeginDraw();
				m_mainClass->render();
				this->EndDraw();
			}

			Engine::instance().m_frameDuration = m_frameDurationCounter.retrieve();
		}

		m_mainClass->deinit();
		Engine::instance().deinitLowLevel();
	}
	catch (EngineError e)
	{
		outputln("Caught EngineError");
		if (this->isDrawing()) this->EndDraw();
		m_isCrashedState = true;

		while (true)
		{
			this->manageEvents();
			Engine::instance().updateInternals();

			this->BeginDraw();
			Engine::instance().clearScreen(CoreUtils::colorBlack);
			Engine::instance().getScene2DMgr().drawText(NULL, Utils::convertWStringToString(e.getFullText(), false).c_str(), Int2(20, 40), 18, CoreUtils::colorWhite);
			this->EndDraw();
			Engine::instance().m_frameDuration = m_frameDurationCounter.retrieve();
		}
	}

	cleanup();

	uninitializeWindow();

	outputln("======== CLEANUP DONE ========");

#ifndef NDEBUG
	// http://gamedev.stackexchange.com/questions/14633/what-do-these-state-creation-warnings-mean-in-the-dx11-debug-output
	typedef HRESULT(__stdcall *fPtr)(const IID&, void**);
	HMODULE hDll = GetModuleHandleW(L"dxgidebug.dll");
	fPtr DXGIGetDebugInterface = (fPtr)GetProcAddress(hDll, "DXGIGetDebugInterface");
	IDXGIDebug* pDxgiDebug;
	DXGIGetDebugInterface(__uuidof(IDXGIDebug), (void**)&pDxgiDebug);
	pDxgiDebug->ReportLiveObjects(DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_ALL);
#endif
}
Ejemplo n.º 3
0
///////////////////////////////////////////////////////////////////////////////////////////////////
/// IvyApp::DeinitDX
///
/// @brief
///     
/// @return
///     N/A
///////////////////////////////////////////////////////////////////////////////////////////////////
bool IvyApp::DeinitDX()
{
    ///@todo Add 'Safe Release' calls or some such to release these components
    if (m_pDxData->pAppRenderTargetView != NULL)
    {
        m_pDxData->pAppRenderTargetView->Release();
    }

    if (m_pDxData->pAppDepthStencilTex != NULL)
    {
        m_pDxData->pAppDepthStencilTex->Destroy();
        m_pDxData->pAppDepthStencilTex = NULL;
    }

    if (m_pDxData->pD3D11Context != NULL)
    {
        m_pDxData->pD3D11Context->Release();
    }

    if (m_pDxData->pD3D11Device != NULL)
    {
        m_pDxData->pD3D11Device->Release();
    }

    if (m_pDxData->pDXGISwapChain != NULL)
    {
        m_pDxData->pDXGISwapChain->Release();
    }

    if (m_pUI)
    {
        m_pUI->Destroy();
        m_pUI = NULL;
    }

    if (m_pUIData->pUserInterfaceVS)
    {
        m_pUIData->pUserInterfaceVS->Destroy();
    }

    if (m_pUIData->pUserInterfacePS)
    {
        m_pUIData->pUserInterfacePS->Destroy();
    }

    if (m_pUIData->pUserInterfaceCameraBuf)
    {
        m_pUIData->pUserInterfaceCameraBuf->Destroy();
    }

    if (m_pUIData->pUserInterfaceQuad)
    {
        m_pUIData->pUserInterfaceQuad->Destroy();
    }

    if (m_pUIData->pUserInterfaceBlendState)
    {
        m_pUIData->pUserInterfaceBlendState->Release();
    }

    if (m_pUIData->pUserInterfaceSRV)
    {
        m_pUIData->pUserInterfaceSRV->Release();
    }

    if (m_pUIData->pUserInterfaceOverlay)
    {
        m_pUIData->pUserInterfaceOverlay->Release();
    }

    if (m_pUIData->pUserInterfaceMutexD3D)
    {
        m_pUIData->pUserInterfaceMutexD3D->Release();
    }

    ///@todo Clean this up, perhaps make it more general
    typedef HANDLE(__stdcall *fPtr)(const IID&, void**);
    HMODULE hDxgiDebug = GetModuleHandle("DXGIDebug.dll");
    fPtr DXGIGetDebugInterface = (fPtr) GetProcAddress(hDxgiDebug, "DXGIGetDebugInterface");

    IDXGIDebug* pDxgiDebug = NULL;
    DXGIGetDebugInterface(__uuidof(IDXGIDebug), (void**)&pDxgiDebug);
    pDxgiDebug->ReportLiveObjects(DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_ALL);

    return true;
}