代码泄漏内存,似乎来自 ID3DXBuffer

发布于 2024-08-12 09:30:51 字数 803 浏览 3 评论 0原文

我使用以下命令加载着色器:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无人问我粥可暖 2024-08-19 09:30:51

注意:即使 DX 函数(例如 D3DXCreateEffectFromFile)没有失败,ID3DXBuffer 也应该被释放。

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

无言温柔 2024-08-19 09:30:51

好吧,我修复了它,这只是一个逻辑问题,“错误”在第三次尝试时没有调用“释放”,因此出现了问题。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文