Hello guys,
I have a little problem.
I have:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | HRESULT makeScreenshot() { HRESULT hr = S_OK; LPDIRECT3DSURFACE9 frontBuffer; int x, y; x = 800; y = 600; if( FAILED( hr = pd3dDevice->CreateOffscreenPlainSurface(x, y, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &frontBuffer, NULL))) return hr;
if( FAILED( hr = pd3dDevice->GetFrontBufferData(NULL, frontBuffer))) { frontBuffer->Release(); return hr; }
D3DXSaveSurfaceToFile(L"Screenshot1.bmp", D3DXIFF_BMP, frontBuffer, NULL, NULL); // D3DXSaveSurfaceToFile(L"Screenshot1.jpg", D3DXIFF_JPG, frontbuf, NULL, &rcWindow);
frontBuffer->Release();
return hr; } |
Compiles well, but when I call the function, the application crushes.
I get:
Unhandled exception at 0x0042c6b6 in application.exe: 0xC0000005: Access violation reading location 0x00000000.
And, this line is marked.
if( FAILED( hr = pd3dDevice->CreateOffscreenPlainSurface(x, y, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &frontBuffer, NULL)))
What am I missing?