IDirect3DDevice9 :: GetFrontBufferData失败,出现分段错误

IDirect3DDevice9 :: GetFrontBufferData失败,出现分段错误

问题描述:

我创建了一个非常简单的DirectX程序来捕获屏幕。它运作良好,我的机器上,但在分段故障(SIGSEV)以下行失败另一台机器上:IDirect3DDevice9 :: GetFrontBufferData失败,出现分段错误

g_pd3dDevice->GetFrontBufferData(0, g_pSurface); 

以下函数用于初始化的DirectX:

HRESULT InitD3D(HWND hWnd) 
{ 
D3DDISPLAYMODE ddm; 
D3DPRESENT_PARAMETERS d3dpp; 

if((g_pD3D=Direct3DCreate9(D3D_SDK_VERSION))==NULL) 
{ 
    ErrorMessage("Unable to Create Direct3D "); 
    return E_FAIL; 
} 

if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&ddm))) 
{ 
    ErrorMessage("Unable to Get Adapter Display Mode"); 
    return E_FAIL; 
} 

ZeroMemory(&d3dpp,sizeof(D3DPRESENT_PARAMETERS)); 

d3dpp.Windowed=WINDOW_MODE; 
d3dpp.Flags=D3DPRESENTFLAG_LOCKABLE_BACKBUFFER; 
d3dpp.BackBufferFormat=ddm.Format; 
d3dpp.BackBufferHeight=nDisplayHeight=gScreenRect.bottom =ddm.Height; 
d3dpp.BackBufferWidth=nDisplayWidth=gScreenRect.right =ddm.Width; 
d3dpp.MultiSampleType=D3DMULTISAMPLE_NONE; 
d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD; 
d3dpp.hDeviceWindow=hWnd; 
d3dpp.PresentationInterval=D3DPRESENT_INTERVAL_DEFAULT; 
d3dpp.FullScreen_RefreshRateInHz=D3DPRESENT_RATE_DEFAULT; 

if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_REF,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING ,&d3dpp,&g_pd3dDevice))) 
{ 
    ErrorMessage("Unable to Create Device"); 
    return E_FAIL; 
} 

if(FAILED(g_pd3dDevice->CreateOffscreenPlainSurface(ddm.Width, ddm.Height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &g_pSurface, NULL))) 
{ 
    ErrorMessage("Unable to Create Surface"); 
    return E_FAIL; 
} 

return S_OK; 
} 

任何想法,为什么这会引发分段错误?

+0

InitD3D返回S_OK,还是会抛出错误消息“无法创建表面”? – NickLH

+0

该方法返回S_OK – Erik

解决方案:DirectX驱动程序安装不正确。