views:

61

answers:

2

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.

A: 

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
+1  A: 

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

Guns