SEH exception with code 0xc0000005 thrown in the test body
Asked Answered
P

11

43

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

class Base
{
    // Other Functions;

    CSig objSig[50];
}

The Class CSig is as follows:

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.

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

Peanuts answered 31/10, 2012 at 12:11 Comment(6)
0xc0000005 is access violation. You need to show us more code (CSig's constructor/destructor possibly).Express
Thanks guys. I have put more code on CSigPeanuts
What is PStrokePrev and does it have space for MAX_NUM doubles?Tenement
Thanks. PStrokePrev is an array of type double and it does have space for MAX_NUM.Peanuts
Were is PStrokePrev declared? Is it dynamically allocated and has it been created before the CSig constructor is called? Why doesn't your constructor initialize objMod or objDemod? The source of the error isn't obvious from the small code snippet you've posted. I'm just pointing out a possible array overrun and uninitialized pointers that could cause the fault.Tenement
This just started happening to me with the latest VS2019, c++17. My colleague found this issue, which is a pending fix at the time of this comment.Knead
H
46

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

Havana answered 31/10, 2012 at 12:32 Comment(4)
Thanks for your reply. Will it help if I change CSig objSig[50] to CSig *objSig and initialise it in the constructor. Thanks.Peanuts
Do you have to use c-style-arrays? If you can, I recommend using STL-containers (esp. std::vector, std::array). In debug mode all accesses are checked which could help you find your bug.Havana
Thanks for your reply. I do not mind using STL-containers. Can you please tell me what are the advantages? Cheers.Peanuts
the advantage is that if you do std::vector<CSig> objSig(50), the elements will be default constructed (or you can emplace the constructed object of your choice). The takeaway is that you should be initializing all the members of this array to actual objectsVitascope
C
19

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.

Countersubject answered 17/3, 2015 at 13:33 Comment(1)
For visual studio 2015: Debug->Windows->Exception SettingsHeighten
M
11

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.

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

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

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.

Miniaturist answered 26/2, 2015 at 22:54 Comment(1)
This answer allowed me to find my problem. I head tested library configured as "Runtime Library: Multi-threaded DLL /MD" and testing app as "Runtime Library: Multi-threaded Debug DLL /MDd". As a result I was getting the same error as in the subject. Thanks.Zacek
H
4

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!

Heighten answered 8/2, 2016 at 13:35 Comment(0)
S
3

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.

Sentiment answered 29/3, 2017 at 3:34 Comment(1)
Confirmed. That fixed the issue. No more un-initialized variables in C++.Sentiment
D
1

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.

Dextrose answered 19/10, 2016 at 15:38 Comment(0)
L
1

destroying null pointer can be a reason. I found out through Visual Studio > Exception > Select All. Then run local windows debugger, it stopped at line where exception occurred.

Liscomb answered 30/12, 2020 at 1:28 Comment(0)
S
0

Ran into this problem using msvc in qt. SEH was thrown almost randomly, for no apparent reasons. (read: didn't have any time left to look into it) After NOT finding the right solution and the tests seemed to work for non-windows users, I switched to MinGW which ran the tests normally.

Sideslip answered 13/12, 2019 at 8:27 Comment(0)
C
0

I was trying to delete a memory address which was already deleted. This was the problem in my case so i suggest to look for null pointers.

Castrate answered 7/5, 2022 at 18:56 Comment(0)
B
0

I am using Gtest with Protobuf on VS and I am seeing the issue where the test's checked(Debug) build was crashing with an exception, but not the free(Release) build.

To use protobuf, I followed instructions here, the vcpkg install for windows in particular.

Turns out Gtest project was inheriting the libs in linker from parent and ended up getting linked to libprotobuf and libprotobuf_lite, and not the libprotobufd and libprotobuf_lited, the latter are the debug versions. This is because by default the path in the Additional Dependencies under Properties->Linker->Input ends up providing the option to link with $(_ZVcpkgCurrentInstalledDir)$(_ZVcpkgConfigSubdir)lib*.lib , which is where the free build of protobuf libs reside.

Changing the path to $(_ZVcpkgCurrentInstalledDir)$(_ZVcpkgConfigSubdir)debug\lib*.lib solved the issue and the exceptions were gone.

Bore answered 8/8, 2023 at 21:9 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Dregs
V
0

I was facing a similar problem. I believed the problem was with the gtest framework, but the problem was actually in the function I was running unit test on.

So, for you it's most probable the problem is in a function that you are testing.

Volley answered 26/9, 2023 at 9:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.