Sign in to follow this  

DirectX9 problem

This topic is 2786 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to learn how to use DirectX9 under Win/XP and I and I have aproblem with multiple windowed view rendering. My windows are created as well as the D3D device. but when I get to the "CreateAdditionalSwapChain" statement, I get an access violation! Any help would be much appreciated... Thanks. LeLorrain Here is the relevant code: HRESULT D3Dgraphics::StartGraphics ( void ) { DEVICEINFO * device = m_D3Denum->getDevice(); COMBOINFO * combo = NULL; if (m_D3Dsystem != NULL) { m_D3Dsystem->Release (); m_D3Dsystem = NULL; } m_D3Dsystem = Direct3DCreate (D3D_SDK_VERSION); if (NULL == m_D3Dsystem) { throw Exception ("D3Dgraphics::StartGraphics", __LINE__, ::GetLastError(), "Graphic system not created"); } // Look for the graphic device for (UINT i = 0; i < device->D3DCombo.size(); i++) { bool Windowed = device->D3DCombo[i].Windowed; if ((device->D3DCombo[i].Windowed == m_Windowed) && (device->D3DCombo[i].D3DDevType == device->D3DDevType) && (device->D3DCombo[i].fmtAdapter == D3DdeviceInfo.AdapterFormat) && (device->D3DCombo[i].fmtBackBuffer == D3DdeviceInfo.BackBufferFmt) ) { combo = &device->D3DCombo[i]; break; } } memset ((void *)&D3DdeviceInfo.D3Dparams, 0, sizeof (D3DdeviceInfo.D3Dparams)); D3DdeviceInfo.D3Dparams.Windowed = m_Windowed; D3DdeviceInfo.D3Dparams.BackBufferCount = 1; D3DdeviceInfo.D3Dparams.BackBufferFormat = D3DdeviceInfo.DisplayMode.Format; D3DdeviceInfo.D3Dparams.EnableAutoDepthStencil = true; D3DdeviceInfo.D3Dparams.AutoDepthStencilFormat = combo->fmtDepthStencil; D3DdeviceInfo.D3Dparams.MultiSampleType = combo->msType; D3DdeviceInfo.D3Dparams.SwapEffect = D3DSWAPEFFECT_DISCARD; // Check the stencil buffer depth if ((D3DFMT_D24S8 == combo->fmtDepthStencil) || (D3DFMT_D24X4S4 == combo->fmtDepthStencil) || (D3DFMT_D16 == combo->fmtDepthStencil) || (D3DFMT_D15S1 == combo->fmtDepthStencil)) { m_Stencil = true; } else { m_Stencil = false; } // Check windowed mode if (m_Windowed) { D3DdeviceInfo.D3Dparams.hDeviceWindow = m_hRenderWnd[0]; D3DdeviceInfo.D3Dparams.BackBufferWidth = m_ScreenWidth; D3DdeviceInfo.D3Dparams.BackBufferHeight = m_ScreenHeight; } else { D3DdeviceInfo.D3Dparams.hDeviceWindow = m_hMainWindow; D3DdeviceInfo.D3Dparams.BackBufferWidth = D3DdeviceInfo.DisplayMode.Width; D3DdeviceInfo.D3Dparams.BackBufferHeight = D3DdeviceInfo.DisplayMode.Height; } // Create the Direct3D device if (NULL == m_D3Dsystem->CreateDevice (device->nAdapter, device->D3DDevType, D3DdeviceInfo.D3Dparams.hDeviceWindow, combo->Behaviour, &D3DdeviceInfo.D3Dparams, &m_D3Ddevice)) { throw Exception ("D3Dgraphics::StartGraphics", __LINE__, ::GetLastError(), "Main Graphics Device NOT Created"); } // Create additional swap chains if required and possible if (m_Windowed && (m_hRenderWnd.size() > 1)) { m_D3Dchains = new LPDIRECT3DSWAPCHAIN[m_hRenderWnd.size()]; for (UINT i = 0; i < m_hRenderWnd.size(); i++) { D3DdeviceInfo.D3Dparams.BackBufferWidth = 0; D3DdeviceInfo.D3Dparams.BackBufferHeight = 0; D3DdeviceInfo.D3Dparams.hDeviceWindow = m_hRenderWnd[i]; m_D3Dchains[i] = NULL; if (NULL == m_D3Ddevice->CreateAdditionalSwapChain (&D3DdeviceInfo.D3Dparams, &(m_D3Dchains[i]))) { int error = ::GetLastError(); std::stringstream os; os << "Additional Graphics Device #" << i <<" NOT Created" << std::ends; throw Exception ("D3Dgraphics::StartGraphics", __LINE__, error, (char *)os.str().c_str()); } } } // Clean Up Enumeration delete m_D3Denum; m_D3Denum = NULL; return SUCCESS; }

Share this post


Link to post
Share on other sites
Your check if CreateDevice works is wrong. You need to check the returned HRESULT, preferrably with the macro SUCCEEDED or FAILED:


if ( SUCCEEDED( m_D3Dsystem->CreateDevice (device->nAdapter, device->D3DDevType, D3DdeviceInfo.D3Dparams.hDeviceWindow, combo->Behaviour, &D3DdeviceInfo.D3Dparams, &m_D3Ddevice ) )

In the end, your m_D3Ddevice pointer was probably NULL due to a creation error.

Share this post


Link to post
Share on other sites
Thanks Endurion for your reply.

Yes, you are right, I should have checked the result with FAILED(), which seems to be the way to do in DirectX!

Further analysis of the HRESULT gave me a "D3DERR_INVALIDCALL" error code ant it seems that the device did not like the multi-sample value of 16 that the enumeration gave me for the combo of the adaptor... Hard-coding the value, I found that it would accept up to 8 samples.

Again, thank you.

LeLorrain

Share this post


Link to post
Share on other sites

This topic is 2786 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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