DirectX9 problem
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.Windowed;
if ((device->D3DCombo.Windowed == m_Windowed) &&
(device->D3DCombo.D3DDevType == device->D3DDevType) &&
(device->D3DCombo.fmtAdapter == D3DdeviceInfo.AdapterFormat) &&
(device->D3DCombo.fmtBackBuffer == D3DdeviceInfo.BackBufferFmt)
) {
combo = &device->D3DCombo;
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;
m_D3Dchains = NULL;
if (NULL == m_D3Ddevice->CreateAdditionalSwapChain (&D3DdeviceInfo.D3Dparams, &(m_D3Dchains))) {
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;
}
Your check if CreateDevice works is wrong. You need to check the returned HRESULT, preferrably with the macro SUCCEEDED or FAILED:
In the end, your m_D3Ddevice pointer was probably NULL due to a creation error.
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.
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement