Jump to content
  • Advertisement
Sign in to follow this  
Belkacem

createswapchain always fail

This topic is 2596 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

hello

i have a problem with create swapchain , and it is always fail , and i dont why i try more than one code and more than way and always fail

first

if i use something like this , it will fail ( the swap chain not create )

::DXGI_SWAP_CHAIN_DESC desc ;
desc.BufferCount = 1 ;
desc.BufferDesc.Format = Buf.Format;
desc.BufferDesc.Height = Buf.Height ;
desc.BufferDesc.RefreshRate = _Mode_Desc->RefreshRate ;
desc.BufferDesc.Scaling = _Mode_Desc->Scaling ;
desc.BufferDesc.ScanlineOrdering = _Mode_Desc->ScanlineOrdering ;
desc.BufferDesc.Width= Buf.Width ;
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH ;
desc.OutputWindow = hwnd ;
desc.SampleDesc = Sample_Desc ;
desc.SwapEffect = ::DXGI_SWAP_EFFECT_DISCARD ;
desc.Windowed= true ;


if ( FAILED (::D3D11CreateDevice ( NULL , D3D_DRIVER_TYPE_HARDWARE , NULL ,D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS| D3D11_CREATE_DEVICE_BGRA_SUPPORT, Feature_Level_List
,_Number_Feature_Level_List , D3D11_SDK_VERSION ,&_Device ,&_featureLevel , &_DeviceContext )))


{
ZeroMemory (&MyError , sizeof(Error));
MyError.Error_Message = L"Sorry ! We Can't Create Device or (and) SwapChain! , we must close";
ErrorMessage ( MyError , __WFILE__ , __LINE__);
return E_FAIL ;
exit(0);
}

IDXGIFactory *pFactory;

CreateDXGIFactory (__uuidof(IDXGIFactory), (void**)&pFactory);

::IDXGISwapChain *Cahin = NULL ;
HRESULT hr = pFactory->CreateSwapChain ( _Device , &desc , &Cahin);



second

but this is work

desc.BufferCount = 1 ;
desc.BufferDesc.Format = Buf.Format;
desc.BufferDesc.Height = Buf.Height ;
desc.BufferDesc.RefreshRate = _Mode_Desc->RefreshRate ;
desc.BufferDesc.Scaling = _Mode_Desc->Scaling ;
desc.BufferDesc.ScanlineOrdering = _Mode_Desc->ScanlineOrdering ;
desc.BufferDesc.Width= Buf.Width ;
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH ;
desc.OutputWindow = hwnd ;
desc.SampleDesc = Sample_Desc ;
desc.SwapEffect = ::DXGI_SWAP_EFFECT_DISCARD ;
desc.Windowed= true ;



/*if ( FAILED (::D3D11CreateDeviceAndSwapChain ( NULL , D3D_DRIVER_TYPE_HARDWARE , NULL ,D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS| D3D11_CREATE_DEVICE_BGRA_SUPPORT, Feature_Level_List
,_Number_Feature_Level_List , D3D11_SDK_VERSION , &_Swp_Chain_desc,&_SwapChain,&_Device ,&_featureLevel , &_DeviceContext )))


{
ZeroMemory (&MyError , sizeof(Error));
MyError.Error_Message = L"Sorry ! We Can't Create Device or (and) SwapChain! , we must close";
ErrorMessage ( MyError , __WFILE__ , __LINE__);
return E_FAIL ;
exit(0);
}*/


whats the wrong in my code i think evry thing is correct !!

another question , can i create more than one swap chain in the same application ??

Share this post


Link to post
Share on other sites
Advertisement
I have a GraphicsDevice class which amongst other things has an IDXGISwapChain* member.

bool GraphicsDevice::Init()
{
UINT flags = 0;
#ifdef _DEBUG
flags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
HRESULT hr = D3D11CreateDevice(
NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
flags,
NULL,
0,
D3D11_SDK_VERSION,
&_pDevice,
&_featureLevel,
&_pImmediateContext);

if(SUCCEEDED(hr)) hr = _pDevice->QueryInterface(__uuidof(IDXGIDevice), reinterpret_cast<void**>(&_pDXGIDevice));

IDXGIAdapter* pDXGIAdapter = NULL;
if(SUCCEEDED(hr)) hr = _pDXGIDevice->GetParent(__uuidof(IDXGIAdapter), reinterpret_cast<void**>(&pDXGIAdapter));

if(SUCCEEDED(hr)) hr = pDXGIAdapter->GetParent(__uuidof(IDXGIFactory), reinterpret_cast<void**>(&_pDXGIFactory));

SAFE_RELEASE(pDXGIAdapter);

return CheckError(hr);
}

IDXGISwapChain* GraphicsDevice::CreateSwapChain(HWND windowHandle, DXGI_FORMAT format, UINT width, UINT height, bool windowed)
{
DXGI_SWAP_CHAIN_DESC sc;
ZeroMemory(&sc, sizeof(DXGI_SWAP_CHAIN_DESC));

sc.BufferCount = 1;
sc.BufferDesc.Width = width;
sc.BufferDesc.Height = height;
sc.BufferDesc.Format = format;
sc.BufferDesc.RefreshRate.Numerator = 60;
sc.BufferDesc.RefreshRate.Denominator = 1;
sc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sc.OutputWindow = windowHandle;
sc.SampleDesc.Count = 1;
sc.SampleDesc.Quality = 0;
sc.Windowed = windowed;

IDXGISwapChain* pSwapChain = NULL;

HRESULT hr = _pDXGIFactory->CreateSwapChain(_pDXGIDevice, &sc, &pSwapChain);

if(CheckError(hr))
{
return pSwapChain;
}
else
{
return NULL;
}
}

Share this post


Link to post
Share on other sites
thanks for your reply

about desc and _swp_chain_dec are equals



_Swp_Chain_desc.BufferCount = 1 ;
_Swp_Chain_desc.BufferDesc.Format = Buf.Format;
_Swp_Chain_desc.BufferDesc.Height = Buf.Height ;
_Swp_Chain_desc.BufferDesc.RefreshRate = _Mode_Desc->RefreshRate ;
_Swp_Chain_desc.BufferDesc.Scaling = _Mode_Desc->Scaling ;
_Swp_Chain_desc.BufferDesc.ScanlineOrdering = _Mode_Desc->ScanlineOrdering ;
_Swp_Chain_desc.BufferDesc.Width= Buf.Width ;
_Swp_Chain_desc.BufferUsage = DXGI_USAGE_BACK_BUFFER;
_Swp_Chain_desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH ;
_Swp_Chain_desc.OutputWindow = hwnd ;
_Swp_Chain_desc.SampleDesc = Sample_Desc ;
_Swp_Chain_desc.SwapEffect = ::DXGI_SWAP_EFFECT_DISCARD ;
_Swp_Chain_desc.Windowed= Windowed ;


::DXGI_SWAP_CHAIN_DESC desc ;
desc.BufferCount = 1 ;
desc.BufferDesc.Format = Buf.Format;
desc.BufferDesc.Height = Buf.Height ;
desc.BufferDesc.RefreshRate = _Mode_Desc->RefreshRate ;
desc.BufferDesc.Scaling = _Mode_Desc->Scaling ;
desc.BufferDesc.ScanlineOrdering = _Mode_Desc->ScanlineOrdering ;
desc.BufferDesc.Width= Buf.Width ;
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH ;
desc.OutputWindow = hwnd ;
desc.SampleDesc = Sample_Desc ;
desc.SwapEffect = ::DXGI_SWAP_EFFECT_DISCARD ;
desc.Windowed= Windowed ;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!