删除对象时可能出现堆损坏问题

发布于 2024-12-04 06:04:51 字数 1975 浏览 0 评论 0 原文

我正在开发一个框架并遇到了一个问题。我注意到由于不删除对象而导致内存泄漏。当我在退出应用程序之前尝试删除此对象时,出现错误,确切地说是这个错误:

关闭应用程序时出错

在我得到这个之后,我

在运行时 抓取了 Application Verifier代码它在以下代码段上设置了一个断点:

PIXELFORMATDESCRIPTOR tPfd = { 
    sizeof(PIXELFORMATDESCRIPTOR), 
    1, 
    PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
    PFD_TYPE_RGBA, 
    32, 
    0, 0, 0, 0, 0, 0, 
    1, 
    0, 
    0, 0, 0, 0, 
    0, 
    24, 
    0, 
    0,
    PFD_MAIN_PLANE,
    0, 
    0, 0, 0
};

unsigned int tFormat = ChoosePixelFormat(g_WindowContext, &tPfd);
if( !tFormat ) {
    LOG( CRITICAL, "Pixelformat could not be choosen." );
    return false;
}

它在“ChoosePixelFormat(g_WindowContext,&tPfd);”行上设置了一个断点并对此有以下“解释”:

VERIFIER STOP 00000301:pid 0x3689C:当前堆栈跟踪使用的 TLS 索引无效。

FFFFFFFF:TLS 索引无效。
0000ABBA:预期索引的下半部分。
00000000:未使用。
00000000:未使用。

我真的不明白发生了什么,这些代码上面的行如下:

g_Window = CreateWindowEx (
    0,
    PROJECT_NAME,                          // window class
    PROJECT_NAME,                          // window title
    tStyle,                          // visibility settings
    tX, tY,
    tW, tH,
    NULL, 
    NULL, 
    tWindowClass.hInstance, 
    NULL
);

if(!g_Window) {
    LOG( CRITICAL, "Window could not be created." );
    return false;
}

g_WindowContext = GetDC(g_Window);
if( !g_WindowContext ) {
    return false;
}

这里使用的变量是:

HDC                     g_WindowContext;
HWND                    g_Window;

我试图删除的对象没什么特别的,应用程序运行时对象不会损坏。我可以使用该对象,我已经尝试使用它的所有功能,并且它们一次又一次地按预期工作。就在我尝试最后删除该对象时,它给出了错误消息。当所有内容都清理完毕后,该对象将在主应用程序循环下方被删除。此时没有任何东西使用它,似乎没有什么问题,当设置断点时,指向对象本身的指针也是有效的。

如果有人能够帮助我,我将不胜感激,如果您需要更多信息或代码片段,请告诉我。

I'm working on a framework and have run into an issue. I noticed that I was leaking memory by not deleting an object. When I tried to delete this object just before exiting the application I get an error, this one to be exact:

Error on closing the application

After I got this I grabbed Application Verifier

When running the code it set a breakpoint on the following piece of code:

PIXELFORMATDESCRIPTOR tPfd = { 
    sizeof(PIXELFORMATDESCRIPTOR), 
    1, 
    PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
    PFD_TYPE_RGBA, 
    32, 
    0, 0, 0, 0, 0, 0, 
    1, 
    0, 
    0, 0, 0, 0, 
    0, 
    24, 
    0, 
    0,
    PFD_MAIN_PLANE,
    0, 
    0, 0, 0
};

unsigned int tFormat = ChoosePixelFormat(g_WindowContext, &tPfd);
if( !tFormat ) {
    LOG( CRITICAL, "Pixelformat could not be choosen." );
    return false;
}

It set a breakpoint on the line with "ChoosePixelFormat(g_WindowContext,&tPfd);" and had the following 'explanation' for it:

VERIFIER STOP 00000301: pid 0x3689C: Invalid TLS index used for current stack trace.

FFFFFFFF : Invalid TLS index.
0000ABBA : Expected lower part of the index.
00000000 : Not used.
00000000 : Not used.

I don't really get what is going on, the lines above these pieces of code are as follows:

g_Window = CreateWindowEx (
    0,
    PROJECT_NAME,                          // window class
    PROJECT_NAME,                          // window title
    tStyle,                          // visibility settings
    tX, tY,
    tW, tH,
    NULL, 
    NULL, 
    tWindowClass.hInstance, 
    NULL
);

if(!g_Window) {
    LOG( CRITICAL, "Window could not be created." );
    return false;
}

g_WindowContext = GetDC(g_Window);
if( !g_WindowContext ) {
    return false;
}

The variables used here are:

HDC                     g_WindowContext;
HWND                    g_Window;

The object I am trying to delete is nothing special, the object is not corrupt while the application is running. I can use the object, I've tried using all its functions and they all work as expected time after time. Just when I try to delete the object at the end it gives the error message. The object is deleted just below the main application loop when everything is cleaned up. Nothing is using it at this point nothing seems to be the problem, when setting a breakpoint the pointer to the object itself is valid as well.

If anybody would be able to help me it would be greatly appreciated, if you need anymore information or pieces of code please let me know.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

莫相离 2024-12-11 06:04:51

如果您尝试在创建对象后立即删除该对象,然后立即退出程序,会发生什么情况?如果您的项目中没有大量代码,只需尝试沿线进一步移动删除/退出,直到它再次开始弹出。您可以通过对所有执行的代码进行分治来加速此过程,以找出损坏的根源。

您能否准确地告诉我们事故发生的地点?一个完整的例子可以帮助我们诊断故障,但是如果没有看到这一点,就很难进一步缩小范围。

What happens if you try deleting the object right after you've created it and then exiting the program immediately? If you've not got masses of code in your project, just try shuffling that delete / exit further along the line until it starts going pop again. You can speed up this process by divide-and-conquering through all the executed code to home in on the source of the corruption.

Can you show us precisely where the crash happens? A complete example would help us diagnose the fault but without seeing that, it's very difficult to narrow it down any further.

音盲 2024-12-11 06:04:51

修复了问题,我删除的最后一个缓冲区是视频内存中的缓冲区,我显然无法删除这个缓冲区。根本没有发生堆损坏,只是逻辑思维缺陷。

感谢那些试图回答这个问题并帮助我的人。

Fixed the problem, the last buffer I was deleting was buffer in video ram, I obviously can't delete this one. No heap corruption going on at all just a logical thinking flaw.

Thank you to the people that tried to answer this one and help me.

雾里花 2024-12-11 06:04:51

您的对象位于堆栈上 - 因此不需要删除。对于需要删除的内容,您需要在 firet 位置使用 new 。

那么代码中的 newdelete 在哪里?

Your objects are on the stack - and therefore do not require deleting. For delete to be required you need to have used new in the firet place.

So where is the new and the delete in your code.

她说她爱他 2024-12-11 06:04:51

您最初的问题包括一个转储,其中包含“VERIFIER STOP 00000301:pid 0x3689C:用于当前堆栈跟踪的无效 TLS 索引。”

如果 VERIFIER 是应用程序验证程序,则可能是原因:

http://support.microsoft.com/kb/842901

症状:当您使用 Windows 应用程序验证程序验证自定义程序时,它可能会停止响应或崩溃。

如果您创建转储文件,该文件将包含 OpenGL32!InitializeThread+043 中的访问冲突条目。

原因:当 OpenGL 在溢出区域的线程本地存储 (TLS) 槽中创建表条目时,会出现此问题。但是,Windows Application Verifier 假定 OpenGL 使用的所有 TLS 插槽都位于主区域中,而不是位于溢出区域中。这会导致 Windows 应用程序验证程序生成访问冲突。

Your original question included a dump with the line "VERIFIER STOP 00000301: pid 0x3689C: Invalid TLS index used for current stack trace. "

If VERIFIER is Application Verifier, then maybe this is the cause:

http://support.microsoft.com/kb/842901

Symptom: When you use Windows Application Verifier to verify a custom-built program, it may stop responding or crash.

If you create a dump file, the file includes an entry for an access violation in OpenGL32!InitializeThread+043.

Cause: This problem occurs when OpenGL creates a table entry in a thread local storage (TLS) slot in the overflow area. However, Windows Application Verifier assumes that all TLS slots that are used by OpenGL are in the primary area, not in the overflow area. This causes Windows Application Verifier to generate an access violation.

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