In my case, with similar symptoms, the issue was the struct alignment mismatch (/Zp option)
I defined for my code a different struct alignment than external libraries (wxWidgets). However, wxWidgets was built with the makefile, so it was compiled using the defaut /Zp. And wxWidget is statically linked.
You can do that, but if you try to delete a wxWidgets-class object from your code the compiler becomes confused about the exact size of struct members. And when running, you get this message:
HEAP[Code.exe]: HEAP: Free Heap block 211a10 modified at 211af8 after it was freed Windows has triggered a breakpoint in Code.exe.
Solution:
Be sure to use the same "Struct Member Alignment" in all code and libraries.
Best rule is to define /ZP to use "default" value. In Visual Studio, under Properties C/C++ Code Generation
MSDN cite: "You should not use this option unless you have specific alignment requirements." See here
Tip: use #pragma pack if you need to control the alignment in some structs See there
Example:
#pragma pack(1) // - 1 byte alignment typedef union { u64 i; struct{ // CUSTOMS.s is used by Folders u32 uidx; // Id, as registered byte isoS, isoT; // isoS/isoT combination. byte udd0, udd1; // custom values (TBD) }s; }CUSTOMS; struct Header // exactly 128 bits { u32 version; u32 stamp; // creation time CUSTOMS customs; // properties } #pragma pack() // this pragma restores the **default** alignment
*
Hope this explanation helps, because this is not actually a bug in code, but a serious configuration mistake: difficult to detect because it is located in subtle compiler options. Thanks for all,