If a thread hook is added whilst on the main thread, then there there is no automatic call to callThreadTerminationHooks.
Instead the hooks are called as part of the module exit scheme.
However, the hooks vector is a thread local variable, which has wound up by the time atexit handling happens, and so accessing vector elements causes a crash.
NB: If ExitModuleObjects() is called at end of main() this avoids the issue.
Fix by spotting hooks added on main thread and track using a separate vector (that is not a thread local).