I guess the following either happened to you, or it was something similar involving unrealised dependencies/headers. Either way, I hope this answer might show up on Google and help some later, extremely confused programmer figure out why they're suddenly observing arbitrary crashes.
So, from experience, this can happen if you compile a new version of SomeObject.o
but accidentally have another object file #include
an old version of SomeObject.hpp
. This leads to corruption, which'll be caused by the compiler referring to outdated member offsets, etc. Sometimes this mostly works and only produces segfaults when destructing objects - either related or seemingly distant ones - and other times the program segfaults right away or somewhere in-between; I've seen several permutations (regrettably!).
For anyone wondering why this can happen, maybe this is just a reflection of how little sleep I get while programming, but I've encountered this pattern in the context of Git submodules, e.g.:
MyRepo
- /
GuiSubmodule
- /
HelperSubmodule
- / /
GuiSubmodule
If (A) you have a new commit in GuiSubmodule
, which has not yet been pulled into HelperSubmodule
's copy, (B) your makefile
compiles MyRepo/uiSubmodule/SomeObject.o
, and (C) another translation unit - either in a submodule or in the main repo via the perils of #include
- links against an older version of SomeObject.hpp
that has a different class layout... You're in for a fun time, and a lot of chasing red herrings until you finally realise the simple mistake.
Since I had cobbled together my build process from scratch, I might've just not been using Git/make
properly - or strictly enough (forgetting to push/pull all submodules). Probably the latter! I see fewer odd bugs nowadays at least :)