Skip to content

SIGSEGV on shutdown #190

Description

@muesli

Shutdown seems to reliably produce an error here:

fish: Job 1, './infinisim' terminated by signal SIGSEGV (Address boundary error)

Activity

  1. NeroBurner commented on Mar 18, 2026

    @NeroBurner
    Collaborator

    I can reproduce. Sim was always a bit wonky, but not sooooo reproducibly segfaulting

  2. sofar commented on Apr 1, 2026

    @sofar

    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  }
          268
    

    or more complex:

    fix-vPortFree-use-after-destruction.patch

  3. preitinger commented on Jun 28, 2026

    @preitinger

    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.

  4. preitinger commented on Jun 28, 2026

    @preitinger

    And, btw, this allocatedMemory is 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.

  5. NeroBurner commented on Jul 5, 2026

    @NeroBurner
    Collaborator

    Patch from @sofar applid in PR #197

    would love some feedback if it works for you (it works for me, but feedback would still be nice 😁 )

  6. self-assigned this
    on Jul 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions