Repository navigation
SIGSEGV on shutdown #190
Description
Activity
I can reproduce. Sim was always a bit wonky, but not sooooo reproducibly segfaulting
During shutdown, destructors are called on a map that is already freed, resulting in the crash.
You can do something like this:
262 /*Run until quit event not arrives*/ 263 if(sdl_quit_qry) { 264 monitor_sdl_clean_up(); 265 - exit(0); 265 + _exit(0); 266 } 267 } 268or more complex:
I suggest a different fix. The problem is that there is no concept for shutting down tasks. They just run in endless while loops. This is fine, there is no need to clean up every bit when the process is stopping anyway, right? But, there should not be a SIGSEV creating an annoying memory dump. So, I suggest to create all global variables that are meant to exist forever, not as for example:
std::unordered_map<void*, size_t> allocatedMemory;But as
std::unordered_map<void*, size_t>* pAllocatedMemory = new std::unordered_map<void*, size_t>(); // and for convenience std::unordered_map<void*, size_t>& allocatedMemory = *pAllocatedMemory;What is the difference here? In the second case the global variable is never destroyed. This is the better behavior when there is no concept how long they can be used in tasks that live actually until the process is killed without any cleanup...
For me, this avoids the annoying SIGSEV that happens on almost every window closing.
And, btw, this
allocatedMemoryis used from different threads without any mutex protection. This can be well-defined, for example if the few accesses from a different thread (I observed 2 different threads accessing this global variable) are all before creating the "main task" where almost all of the further accesses seem to happen, but does not have to.
Shutdown seems to reliably produce an error here: