Ms Visual Studio 上的 C++ 错误:“Windows 已触发 javaw.exe 中的断点”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10172436/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 13:42:37  来源:igfitidea点击:

C++ error on Ms Visual Studio: "Windows has triggered a breakpoint in javaw.exe"

c++visual-studio-2008

提问by DavideChicco.it

I've been always working on my software C++ & Java (build with Microsoft Visual Studio 2008 & Eclipse), and I've been trying to move it from a 32-bit system to a 64-bit one.

我一直在研究我的软件 C++ 和 Java(使用 Microsoft Visual Studio 2008 和 Eclipse 构建),并且我一直试图将它从 32 位系统转移到 64 位系统。

The compilation phase is alright, but on execution I get an error that says:

编译阶段没问题,但在执行时我收到一个错误消息:

"Windows has triggered a breakpoint in javaw.exe. This may be due to corruption of the heap, which indicates a bug in javaw.exe or any of the DLLs it has loaded-. This may also be due to user pressing F12 while javaw.exe has focus. The output window may have more diagnostic information. [BREAK] [CONTINUE] [IGNORE]"

“Windows 在 javaw.exe 中触发了一个断点。这可能是由于堆损坏,这表明 javaw.exe 或它已加载的任何 DLL 中存在错误。这也可能是由于用户在 javaw 时按 F12 .exe 具有焦点。输出窗口可能有更多诊断信息。[BREAK] [CONTINUE] [IGNORE]”

You can see a snapshot of the error here:

您可以在此处查看错误快照:

enter image description here

在此处输入图片说明

Have you any idea of what this error means? What does "corruption of the heap" mean? Have you evere had any experience with this kind of error before?

你知道这个错误意味着什么吗?“堆损坏”是什么意思?你以前有过这种错误的经历吗?

Thank you so much!

非常感谢!

回答by Hans Passant

It is a very nice feature of the Windows heap allocator, available since Vista. It tells you that your code has a pointer bug. Well, hopefully it is your code and not the JVM that has the bug :) You'd better assume it is your code.

这是 Windows 堆分配器的一个非常好的特性,从 Vista 开始可用。它告诉你你的代码有一个指针错误。好吧,希望是您的代码而不是有错误的 JVM :) 您最好假设它是您的代码。

The actual cause ranges somewhere between mild, like trying to free memory that was already freed or allocated from another heap (not uncommon when you interop with another program), to drastically nasty, like having blown the heap to pieces earlier by overflowing a heap allocated buffer.

实际原因介于轻微之间,例如尝试释放已经从另一个堆释放或分配的内存(当您与另一个程序互操作时并不少见),到非常令人讨厌的情况,例如通过溢出分配的堆提前将堆炸成碎片缓冲。

The diagnostic is not fine-grained enough to tell you exactly what went wrong, just that there's something wrong. You typically chase it down with a careful code review and artificially disabling chunks of code until the error disappears. Such are the joys of explicit memory management. If the 32-bit version is clean (check it) then this can be associated with 64-bit code due to assumptions about pointer size. A 64-bit pointer doesn't fit in an int or long, so it is going to get truncated. And using the truncated pointer value is going to trigger this assert. That's the happy kind of problem, you'll find the trouble code back in the Call Stack window.

诊断的粒度不够细,无法准确地告诉您出了什么问题,只是出了点问题。您通常通过仔细的代码和人为地禁用代码块来追踪它,直到错误消失。这就是显式内存管理的乐趣所在。如果 32 位版本是干净的(检查它),那么由于对指针大小的假设,这可能与 64 位代码相关联。64 位指针不适合 int 或 long,因此它会被截断。使用截断的指针值将触发此断言。这是令人愉快的问题,您会在“调用堆栈”窗口中找到故障代码。

回答by Luchian Grigore

This unfortunately usually means a memory corruption. Some double freeing of memory, function that should return but doesn't or any other type of undefined behavior.

不幸的是,这通常意味着内存损坏。一些内存的双重释放,应该返回但不返回的函数或任何其他类型的未定义行为。

Your best bet of solving this, unless you have a clue as to where this corruption is, is to use a memory analysis tool.

解决此问题的最佳选择是使用内存分析工具,除非您知道此损坏的位置。

回答by DavideChicco.it

I got it! Thanks to you all, I understood it was a problem of memory, and maybe of malloc() In fact, I read here:

我知道了!感谢大家,我明白这是内存问题,也许是 malloc() 事实上,我在这里读到:

The bucket-sizing factor must be a multiple of 8 for 32-bit implementations and a multiple of 16 for 64-bit implementations in order to guarantee that addresses returned from malloc subsystem functions are properly aligned for all data types.

IBM.com:

存储桶大小因子对于 32 位实现必须是 8 的倍数,对于 64 位实现必须是 16 的倍数,以确保从 malloc 子系统函数返回的地址对于所有数据类型都正确对齐。

IBM.com:

So, I changed the malloc() sizing in the problem point. I went from:

因此,我更改了问题点中的 malloc() 大小。我从:

(int**) malloc (const * sizeof(int))

(int**) malloc (const * sizeof(int))

to:

到:

(int**) malloc (const * sizeof(int64_t))

(int**) malloc (const * sizeof(int64_t))

And now it works!

现在它起作用了!

Thanx a lot!

非常感谢!

回答by tukaef

Typically that kind of errors occurs when you trying to access the memory you didn't allocate. Check out all of your allocations (and freeing), especially pointer-to-pointer, and code that can access dinamically allocated memory. In your case size of poiners is 64bit insdead of 32bit, that should be prime cause.

通常,当您尝试访问未分配的内存时会发生这种错误。检查所有分配(和释放),尤其是指针到指针,以及可以访问动态分配内存的代码。在您的情况下,指针的大小是 64 位而不是 32 位,这应该是主要原因。