0

I load a shader with the following:

ID3DXBuffer* errors = 0;
ID3DXEffect* effect = 0;

HR(D3DXCreateEffectFromFile(
    gd3dDevice,  L"Shader.fx", 0, 0,
    D3DXSHADER_DEBUG|D3DXSHADER_SKIPOPTIMIZATION,
    0, &effect, &errors));

for (int i = 0; i < 3; i++)  {
    if(errors) {
        errors->Release();
        if (effect)
            effect->Release();

        errors = 0;
        HR(D3DXCreateEffectFromFile(gd3dDevice, L"Shader.fx", 
            0, 0, D3DXSHADER_DEBUG, 0, effect, &errors));
    }
    else
        break;
}

Which is trying to load a shader and if it gets an error/warning it tries again 3 more times before giving up.

Now I've found when I close the application D3DX gives me the following message:

D3DX: MEMORY LEAKS DETECTED: 2 allocations unfreed (486 bytes)

and this ONLY happens when there are errors (i.e. it goes into the loop). I'm really not sure why this is happening, any ideas?

OK I fixed it, was just a logic issue, 'error' didn't have 'release' called on it on the third try hence the issue.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
meds
  • 21,699
  • 37
  • 163
  • 314

2 Answers2

2

Note: ID3DXBuffer should be released even when DX function (ex. D3DXCreateEffectFromFile) didn't fail.

Guns
  • 21
  • 3
0

OK I fixed it, was just a logic issue, 'error' didn't have 'release' called on it on the third try hence the issue.

meds
  • 21,699
  • 37
  • 163
  • 314
  • Still, if available on your system I would try to use something like CComPtr instead of raw pointers for holding these interfaces. – Robinson May 27 '11 at 14:29
  • With the Windows 8.0 SDK that comes with VS 2012 or Windows 8.1 SDK that comes with VS 2013, you can use ``Microsoft::WRL::ComPtr`` that doesn't have any dependencies on a DLL, WinRT, or the ATL. It's basically the same as ATL's ``CComPtr`` but is a bit more robust. – Chuck Walbourn Dec 10 '14 at 00:41