代码在调试中不起作用

时间:2022-05-23 20:26:12

i coded a big project in c++ that runs when I open it in Debug or Release Mode, but when i open it without Debugging (ctrl + f5) it crashs after 5 seconds. It just doesn't reply anymore and is tagged as inactive in taskmanager. I tried to analyse the error with the windows debugger tools and application verfier, but i found nothing. Even when I set the "_NO_DEBUG_HEAP=1", the error doesn't occur, it just happens when I start it with ctrl + f5 or outside from visual studio. I'm not even sure if the _NO_DEBUG_HEAP works... Anyone have an idea what could be wrong ?

我编写了一个用c ++编写的大项目,当我在调试或发布模式下打开它时运行,但是当我打开它而没有调试(ctrl + f5)时它会在5秒后崩溃。它只是不再回复,并在taskmanager中被标记为非活动状态。我尝试用Windows调试器工具和应用程序verfier分析错误,但我什么都没发现。即使我设置了“_NO_DEBUG_HEAP = 1”,也不会发生错误,只是当我用ctrl + f5启动它或者从visual studio开始它时。我甚至不确定_NO_DEBUG_HEAP是否有效......任何人都知道可能出现什么问题?

2 个解决方案

#1


Any number of things may cause this.

任何事情都可能导致这种情况。

Based on my passed experience, I suggest tackling this by removing code until the behaviour disappears... then determining why removing the code in question corrected the behaviour. (the removed code may not have been the cause, only a catalyst for the symptom)

根据我的经验,我建议通过删除代码来解决这个问题,直到行为消失为止......然后确定为什么删除有问题的代码会纠正行为。 (删除的代码可能不是原因,只是症状的催化剂)

If I was tasked with taking a quick glance to spot the error, I would think to look for buffer overrun related issues. This type of error has more safeguards in debug than executing a final build. That's just a stab in the dark based on buffer overruns being a common issue that kinda fits the symptom.

如果我的任务是快速浏览一下发现错误,我会考虑寻找与缓冲区溢出相关的问题。与执行最终构建相比,此类错误在调试中具有更多安全措施。基于缓冲区溢出是一个有点适合症状的常见问题,这只是黑暗中的刺伤。

-dm

#2


Common things to check:

要检查的常见事项:

Are you sure your application is setting any memory used to zero, if it is assuming the memory has to be zeroed out?

如果假设内存必须归零,你确定你的应用程序正在设置任何用于零的内存吗?

Visual Studio might be initializing the memory given to the application.

Visual Studio可能正在初始化为应用程序提供的内存。

Is all the memory allocated being deallocated?

分配的所有内存是否已取消分配?

There are no un-initialized pointers being used?

没有使用未初始化的指针?

There are no un-initialized variables being used?

没有使用未初始化的变量?

64 bit exe crashing outside visual studio but working inside visual studio

64位exe在视觉工作室外崩溃,但在视觉工作室内工作

Does the problem only happen on one computer?

问题只发生在一台计算机上吗?

You can use check_heap to check the validity of the heap in the program:

您可以使用check_heap检查程序中堆的有效性:

Program crashes only in Release mode outside debugger

程序仅在调试器外部的发布模式下崩溃

You can use the Windows debugging tools to show heap corruption - there is a tool called "gflags" that comes with the Microsoft "Standalone Debugging Tools for Windows"

您可以使用Windows调试工具来显示堆损坏 - Microsoft的“Windows独立调试工具”附带了一个名为“gflags”的工具

https://msdn.microsoft.com/en-us/windows/hardware/hh852365

This URL shows how to run gflags against your .EXE:

此URL显示如何针对.EXE运行gflags:

Visual Studio - how to find source of heap corruption errors

Visual Studio - 如何查找堆损坏错误的来源

#1


Any number of things may cause this.

任何事情都可能导致这种情况。

Based on my passed experience, I suggest tackling this by removing code until the behaviour disappears... then determining why removing the code in question corrected the behaviour. (the removed code may not have been the cause, only a catalyst for the symptom)

根据我的经验,我建议通过删除代码来解决这个问题,直到行为消失为止......然后确定为什么删除有问题的代码会纠正行为。 (删除的代码可能不是原因,只是症状的催化剂)

If I was tasked with taking a quick glance to spot the error, I would think to look for buffer overrun related issues. This type of error has more safeguards in debug than executing a final build. That's just a stab in the dark based on buffer overruns being a common issue that kinda fits the symptom.

如果我的任务是快速浏览一下发现错误,我会考虑寻找与缓冲区溢出相关的问题。与执行最终构建相比,此类错误在调试中具有更多安全措施。基于缓冲区溢出是一个有点适合症状的常见问题,这只是黑暗中的刺伤。

-dm

#2


Common things to check:

要检查的常见事项:

Are you sure your application is setting any memory used to zero, if it is assuming the memory has to be zeroed out?

如果假设内存必须归零,你确定你的应用程序正在设置任何用于零的内存吗?

Visual Studio might be initializing the memory given to the application.

Visual Studio可能正在初始化为应用程序提供的内存。

Is all the memory allocated being deallocated?

分配的所有内存是否已取消分配?

There are no un-initialized pointers being used?

没有使用未初始化的指针?

There are no un-initialized variables being used?

没有使用未初始化的变量?

64 bit exe crashing outside visual studio but working inside visual studio

64位exe在视觉工作室外崩溃,但在视觉工作室内工作

Does the problem only happen on one computer?

问题只发生在一台计算机上吗?

You can use check_heap to check the validity of the heap in the program:

您可以使用check_heap检查程序中堆的有效性:

Program crashes only in Release mode outside debugger

程序仅在调试器外部的发布模式下崩溃

You can use the Windows debugging tools to show heap corruption - there is a tool called "gflags" that comes with the Microsoft "Standalone Debugging Tools for Windows"

您可以使用Windows调试工具来显示堆损坏 - Microsoft的“Windows独立调试工具”附带了一个名为“gflags”的工具

https://msdn.microsoft.com/en-us/windows/hardware/hh852365

This URL shows how to run gflags against your .EXE:

此URL显示如何针对.EXE运行gflags:

Visual Studio - how to find source of heap corruption errors

Visual Studio - 如何查找堆损坏错误的来源