# Using ID3D10Resource question

## Recommended Posts

lomateron    491

I am doing this code:

ID3D10Resource* reSo;

g_pd3dDevice->CopyResource(Text1,reSo);

g_pd3dDevice->CopyResource(Text2,reSo);


My question is, Where do i have to call Release()?
IS it like THIS:

ID3D10Resource* reSo;

g_pd3dDevice->CopyResource(Text1,reSo);
reSo->Release();

g_pd3dDevice->CopyResource(Text2,reSo);
reSo->Release();


or like THIS:

ID3D10Resource* reSo;

g_pd3dDevice->CopyResource(Text1,reSo);

g_pd3dDevice->CopyResource(Text2,reSo);

reSo->Release();
reSo->Release();


##### Share on other sites
mhagain    13430

Do it the first way.  The pointer returned by GetResource is going to be different for each call (as GetResource is called on a different shader resource each time), so by doing it the second way you'll (1) leak the resource returned by your first GetResource call, (2) actually destroy the resource returned by your second, and (3) risk crashing when you come to clean up the second for real.

Edited by mhagain