Reputation: 6488
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.
Upvotes: 44
Views: 96946
Reputation: 552
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.
Upvotes: 0
Reputation: 1
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.
Upvotes: 0
Reputation: 427
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.
Upvotes: 0
Reputation: 11
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.
Upvotes: 1
Reputation: 657
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.
Upvotes: 0
Reputation: 4789
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.
Upvotes: 3
Reputation: 51
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.
Upvotes: 1
Reputation: 16204
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!
Upvotes: 5
Reputation: 3881
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.
Upvotes: 20
Reputation:
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.
Upvotes: 12
Reputation: 3460
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
Upvotes: 47