[d3d9] GetSwapChain segfaults?

Started by
5 comments, last by AverageJoeSSU 12 years, 12 months ago
simple as that...

trying to copy contents of backbuffer to texture and getting this error when i get the swap chain from the device....

IDirect3DDevice9 *pd3dDevice = pCtx->Get3DDevice();

IDirect3DSwapChain9 **pSwapChain;
res = pd3dDevice->GetSwapChain(0, pSwapChain);

the hresult seems to return 0?

do i need to do something special before a nab the swapchain?

-Thanks!

------------------------------

redwoodpixel.com

Advertisement
It should be:

IDirect3DSwapChain9 *pSwapChain;

res = pd3dDevice->GetSwapChain(0, &pSwapChain);
<-------noob

------------------------------

redwoodpixel.com

For added safety:
IDirect3DSwapChain9 *pSwapChain = NULL;

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Is there anything more you have to do for this to work?

Or any weird things worth noting?


I call UpdateSurface and then SAFE_RELEASE(surface); yet my texture seems to always be black.


IDirect3DTexture9* tex = pRes->GetTexture();

IDirect3DSurface9* pTmpSurf;
tex->GetSurfaceLevel( 0, &pTmpSurf );

RECT r = {bx,by,bw,bh};
// fprintf()


IDirect3DSurface9* swapSurface;
pSwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &swapSurface);
res = pd3dDevice->UpdateSurface( swapSurface, &r, pTmpSurf, NULL );

SAFE_RELEASE( pTmpSurf );



------------------------------

redwoodpixel.com

Be sure to read the documentation properly: http://msdn.microsoft.com/en-us/library/bb205857(VS.85).aspx

In particular:

This function has the following restrictions.

The source surface must have been created with D3DPOOL_SYSTEMMEM.
The destination surface must have been created with D3DPOOL_DEFAULT.
Neither surface can be locked or holding an outstanding device context.
Neither surface can be created with multisampling. The only valid flag for both surfaces is D3DMULTISAMPLE_NONE.
The surface format cannot be a depth stencil format.
The source and dest rects must fit within the surface.
No stretching or shrinking is allowed (the rects must be the same size).
The source format must match the dest format.
[/quote]

Also, you must release the swapSurface too, and use the SUCCEEDED or FAILED macros to check which if any calls fail.

You might want to look into StretchRect: http://msdn.microsoft.com/en-us/library/bb174471(VS.85).aspx
Or UpdateTexture: http://msdn.microsoft.com/en-us/library/bb205858(VS.85).aspx

What exactly are you trying to achieve?
I need the destination color for my shader for correct blending, and cannot use regular blending because I need to deal with gamma correction. dry.gif

I was planning on doing this with an RTT backbuffer, but found that we use a surface config for our backbuffer for possible performance reasons.

I'll double check and make sure i meet the spec in the docs.......

------------------------------

redwoodpixel.com

This topic is closed to new replies.

Advertisement