代码泄漏内存,似乎来自 ID3DXBuffer
我使用以下命令加载着色器:
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;
}
它正在尝试加载着色器,如果收到错误/警告,它会在放弃之前再尝试 3 次。
现在我发现,当我关闭应用程序时,D3DX 会给出以下消息:
D3DX:检测到内存泄漏:2 个分配未释放(486 字节)
,并且只有在出现错误时才会发生这种情况(即,它进入循环)。我真的不确定为什么会发生这种情况,有什么想法吗?
好吧,我修复了它,这只是一个逻辑问题,“错误”在第三次尝试时没有调用“释放”,因此出现了问题。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
注意:即使 DX 函数(例如 D3DXCreateEffectFromFile)没有失败,ID3DXBuffer 也应该被释放。
Note: ID3DXBuffer should be released even when DX function (ex. D3DXCreateEffectFromFile) didn't fail.
好吧,我修复了它,这只是一个逻辑问题,“错误”在第三次尝试时没有调用“释放”,因此出现了问题。
OK I fixed it, was just a logic issue, 'error' didn't have 'release' called on it on the third try hence the issue.