A little bugfix for Windows users not using Win client...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PowerWyrm
    Prophet
    • Apr 2008
    • 2986

    A little bugfix for Windows users not using Win client...

    As I discovered when using SDL and GCU clients on Windows, the "quit" hook is not called when closing the console (resulting in a lot of memory not being freed) because the CTRL_CLOSE_EVENT is not handled.

    The code below fixes that problem nicely. Declare a control handler function in the main-xxx file:

    Code:
    static BOOL CtrlHandler(DWORD fdwCtrlType)
    {
        switch (fdwCtrlType)
        {
            case CTRL_CLOSE_EVENT:
                quit(NULL);
                return FALSE;
            default:
                return FALSE;
        }
    }
    And call it in the init_xxx function:

    Code:
        /* Activate hooks */
        plog_aux = hook_plog;
        quit_aux = hook_quit;
    
        /* Register a control handler */
        if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE))
            quit("Could not set control handler");
    Et voila! Closing the Windows Console now calls hook_quit(), which should call cleanup_angband() and free allocated memory properly.
    PWMAngband variant maintainer - check https://github.com/draconisPW/PWMAngband (or http://www.mangband.org/forum/viewforum.php?f=9) to learn more about this new variant!
Working...
😀
😂
🥰
😘
🤢
😎
😞
😡
👍
👎