代码为0xc0000005的SEH异常在测试体中抛出

时间:2022-06-18 20:27:44

I am writing a test using GoogleTest for the following class and I am getting the above error.

我正在使用GoogleTest为以下课程编写测试,我收到了上述错误。

class Base
{
    // Other Functions;

    CSig objSig[50];
}

The Class CSig is as follows:

Class CSig如下:

class CSig
{
    //... constructor, destructor(empty) and some functions
    CMod *objMod;
    CDemod *objDemod;
}

CSig :: CSig
{
    bIsInitialised = false;

    for (int i=0; i<MAX_NUM; i++)
    {
        PStrokePrev[i] = 0.0;
    }
}

However, when I discard CSig objSig[50], the tests run fine.

但是,当我丢弃CSig objSig [50]时,测试运行正常。

What can I do to solve this issue? Also, I need to have CSig objSig[50] in the Base class.

我该怎么做才能解决这个问题?另外,我需要在Base类中使用CSig objSig [50]。

6 个解决方案

#1


23  

A SEH (Structured Exception Handling) exception is not a C++-exception that can be handled using c++-language constructs (try-catch) but it is raised from windows itself and points to some fundamental flaw. SEH-exceptions are very annoying because they do not cause normal stack unwinding which can lead to unclosed files or not-unlocked mutexes that should normally cleared by the destructors of the owning object. I have encountered SEH-exceptions when accessing memory that does not belong to the current process so I recommend looking at memory-related instructions in the constructor and destructor of CSig. You can read about SEH, for instance, here

SEH(结构化异常处理)异常不是C ++ - 可以使用c ++语言结构(try-catch)处理的异常,但它是从windows本身引发的,并指向一些基本缺陷。 SEH-异常非常烦人,因为它们不会导致正常的堆栈展开,这可能导致未关闭的文件或未解锁的互斥锁,这些互斥锁通常应由拥有对象的析构函数清除。我在访问不属于当前进程的内存时遇到了SEH异常,所以我建议在CSig的构造函数和析构函数中查看与内存相关的指令。例如,您可以在此处阅读有关SEH的信息

#2


10  

The way I just found the problem was that in Visual Studio I went to Debug->Exceptions, and checked everything in the first column. Then run/debug your unit tests, and it will throw an exception on the line that the problem is at. That's where you need to debug/fix it.

我刚刚发现问题的方法是在Visual Studio中我去了Debug-> Exceptions,并检查了第一列中的所有内容。然后运行/调试您的单元测试,它将在问题所在的行上引发异常。这就是你需要调试/修复它的地方。

#3


5  

I ran into this very problem using GoogleTest with Visual Studio 2010. Our setup involves creating a library for the GoogleTest Frameworks, which is then linked against our individual Unit Tests. I recently updated the Frameworks support and recompiled it from scratch. After doing this, I encountered the exception described above.

我在Visual Studio 2010中使用GoogleTest遇到了这个问题。我们的设置包括为GoogleTest框架创建一个库,然后将其链接到我们各自的单元测试。我最近更新了Frameworks支持并从头开始重新编译它。执行此操作后,我遇到了上述异常。

After a bit of digging, I discovered that the 'Struct Member Alignment' setting was the culprit:

经过一番挖掘后,我发现'Struct Member Alignment'设置是罪魁祸首:

Project properties > Configuration Properties > C/C++ > Code Generation > Struct Member Alignment

项目属性>配置属性> C / C ++>代码生成>结构成员对齐

While the Frameworks project had the setting set to 'default', the corresponding Unit Test project had it configured to "1 Byte /Zp1". Once I changed them to have the same alignment, the problem went away.

虽然Frameworks项目的设置设置为“default”,但相应的Unit Test项目将其配置为“1 Byte / Zp1”。一旦我将它们更改为具有相同的对齐方式,问题就会消失。

#4


2  

For me it appeared to be a null reference error. Some method was called on a nullptr and for reasons unclear to me it didn’t fail immediately but just started executing. The SEH error presumably occurred as soon as unallocated memory was accessed. So check for null pointers!

对我来说,它似乎是一个空引用错误。在nullptr上调用了一些方法,由于我不明白的原因,它没有立即失败但只是开始执行。一旦访问了未分配的内存,就可能发生SEH错误。所以检查空指针!

#5


1  

I am having a similar issue and its pertaining to un-initialized variables and running the test in release build. I had a char * un-initialized after which initialized to NULL seems to have fixed the issue.

我遇到了类似的问题,它与未初始化的变量有关,并在发布版本中运行测试。我有一个未初始化的char *,之后初始化为NULL似乎解决了这个问题。

#6


0  

If you are using Visual Studio 2013, check the Thrown box for Win32 exceptions (specifically access violation) in Debug>Exceptions. This will let you debug which line has the issue. This might be useful since the debugger will not break if your program normally raises other exceptions.

如果您使用的是Visual Studio 2013,请在“调试”>“例外”中检查“Winr异常”(特别是访问冲突)的“投掷”框。这将让您调试哪一行有问题。这可能很有用,因为如果程序通常引发其他异常,调试器不会中断。

#1


23  

A SEH (Structured Exception Handling) exception is not a C++-exception that can be handled using c++-language constructs (try-catch) but it is raised from windows itself and points to some fundamental flaw. SEH-exceptions are very annoying because they do not cause normal stack unwinding which can lead to unclosed files or not-unlocked mutexes that should normally cleared by the destructors of the owning object. I have encountered SEH-exceptions when accessing memory that does not belong to the current process so I recommend looking at memory-related instructions in the constructor and destructor of CSig. You can read about SEH, for instance, here

SEH(结构化异常处理)异常不是C ++ - 可以使用c ++语言结构(try-catch)处理的异常,但它是从windows本身引发的,并指向一些基本缺陷。 SEH-异常非常烦人,因为它们不会导致正常的堆栈展开,这可能导致未关闭的文件或未解锁的互斥锁,这些互斥锁通常应由拥有对象的析构函数清除。我在访问不属于当前进程的内存时遇到了SEH异常,所以我建议在CSig的构造函数和析构函数中查看与内存相关的指令。例如,您可以在此处阅读有关SEH的信息

#2


10  

The way I just found the problem was that in Visual Studio I went to Debug->Exceptions, and checked everything in the first column. Then run/debug your unit tests, and it will throw an exception on the line that the problem is at. That's where you need to debug/fix it.

我刚刚发现问题的方法是在Visual Studio中我去了Debug-> Exceptions,并检查了第一列中的所有内容。然后运行/调试您的单元测试,它将在问题所在的行上引发异常。这就是你需要调试/修复它的地方。

#3


5  

I ran into this very problem using GoogleTest with Visual Studio 2010. Our setup involves creating a library for the GoogleTest Frameworks, which is then linked against our individual Unit Tests. I recently updated the Frameworks support and recompiled it from scratch. After doing this, I encountered the exception described above.

我在Visual Studio 2010中使用GoogleTest遇到了这个问题。我们的设置包括为GoogleTest框架创建一个库,然后将其链接到我们各自的单元测试。我最近更新了Frameworks支持并从头开始重新编译它。执行此操作后,我遇到了上述异常。

After a bit of digging, I discovered that the 'Struct Member Alignment' setting was the culprit:

经过一番挖掘后,我发现'Struct Member Alignment'设置是罪魁祸首:

Project properties > Configuration Properties > C/C++ > Code Generation > Struct Member Alignment

项目属性>配置属性> C / C ++>代码生成>结构成员对齐

While the Frameworks project had the setting set to 'default', the corresponding Unit Test project had it configured to "1 Byte /Zp1". Once I changed them to have the same alignment, the problem went away.

虽然Frameworks项目的设置设置为“default”,但相应的Unit Test项目将其配置为“1 Byte / Zp1”。一旦我将它们更改为具有相同的对齐方式,问题就会消失。

#4


2  

For me it appeared to be a null reference error. Some method was called on a nullptr and for reasons unclear to me it didn’t fail immediately but just started executing. The SEH error presumably occurred as soon as unallocated memory was accessed. So check for null pointers!

对我来说,它似乎是一个空引用错误。在nullptr上调用了一些方法,由于我不明白的原因,它没有立即失败但只是开始执行。一旦访问了未分配的内存,就可能发生SEH错误。所以检查空指针!

#5


1  

I am having a similar issue and its pertaining to un-initialized variables and running the test in release build. I had a char * un-initialized after which initialized to NULL seems to have fixed the issue.

我遇到了类似的问题,它与未初始化的变量有关,并在发布版本中运行测试。我有一个未初始化的char *,之后初始化为NULL似乎解决了这个问题。

#6


0  

If you are using Visual Studio 2013, check the Thrown box for Win32 exceptions (specifically access violation) in Debug>Exceptions. This will let you debug which line has the issue. This might be useful since the debugger will not break if your program normally raises other exceptions.

如果您使用的是Visual Studio 2013,请在“调试”>“例外”中检查“Winr异常”(特别是访问冲突)的“投掷”框。这将让您调试哪一行有问题。这可能很有用,因为如果程序通常引发其他异常,调试器不会中断。