IDirect3DDevice9::GetFrontBufferData fails with segmentation fault

只谈情不闲聊 提交于 2019-12-13 04:24:29

问题


I created a really simple DirectX program to capture the screen. It works well on my machine, but fails on another machine in the following line with a segmentation fault (SIGSEV):

g_pd3dDevice->GetFrontBufferData(0, g_pSurface);

The following function is used to initialize 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;
}

Any ideas why this would throw a segmentation fault?


回答1:


Solution: The DirectX driver was not correctly installed.



来源:https://stackoverflow.com/questions/8158027/idirect3ddevice9getfrontbufferdata-fails-with-segmentation-fault

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!