Reputation: 1613
What is going on?! I fixed some structs, extensive amount of search/replace in my code. Then i finish and everything compiles fine, but the program crashes immediately.
This is my main function:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
exit(1);
In all logics it shouldnt crash, since im not executing any functions. only WinMain(), which does nothing!
What the hell? And why its not giving me the line numbers anymore? its giving the location in the external include files, not the line in MY code.
Also i noticed my EXE size is now 5 times smaller than it was before, which also doesnt make sense, looks like it stops compiling at some point, but still says its compiled!
Edit: this is what i get from the error:
File: ... \include\xstring
Line: 1084
Expression: Invalid null pointer
When i run it in non-debug mode i get First-chance exception at 0x00413a95 ....: 0xC0000005: Access violation reading location 0x00000000.
--
Edit2: reason found: I initialized a global struct in the following way: const StructName VarName = {1, 1, 1};
but the StructName Struct was changed.
Upvotes: 2
Views: 393
Reputation: 6846
As @sbi said, it's likely global/static objects. In my experience, this (often?) happens if a string object is in a global scope which is referenced by other global object/initialization code. Due to non-deterministic initialization order, the string can be used before it has been constructed. I'd look for those cases (well, and avoid global code if possible).
On a side note, this can happen with any objects, not just strings. It's usually not that the object wasn't initialized properly, but rather that something is using it before it's initialized (although @sbi's answer could also be the cause).
Upvotes: 0
Reputation: 224079
Constructors for global and static objects are invoked before a program starts. (I'm not sure how this interacts with WinMain()
, though.)
Run your application under the debugger to see how it crashes.
From your added description it seems as if a std::string
is initialized with a NULL
pointer, which isn't allowed. Do you have a global/static string that's initialized with NULL
/0
? This typically happens when you change a variable's type from char*
(or char[]
) to std::string
.
Upvotes: 2