• MorphOS Developer
    Piru
    Posts: 582 from 2003/2/24
    From: finland, the l...
    Quote:

    BalrogSoft wrote:
    Anyway I have found a solution, RemTask(0) as a Exit alternative make it working!

    That won't work correctly I'm afraid (it will nuke the shell when started from it, and leak WBStartupMsg if ran from Ambient).

    This should do the trick however:

    1. Only check for ESC in keys function. If it is found signal self with CTRL-C signal, telling glutMainLoop that the app is terminating:

    Code:

    static void keys(unsigned char c, int x, int y)
    {
    if (c == 0x1b)
    {
    Signal(FindTask(0), SIGBREAKF_CTRL_C);
    }
    }


    2. Move cleanup that is in keys() function after glutMainLoop() call in main()/entry().




    PS. Currently the app cannot be run safely from Ambient if compiled with NOSTARTUPFILES. For that to work you'd need to handle WBStartupMsg manually. Something like:

    Code:

    #ifdef NOSTARTUPFILES
    int entry(void)
    {
    SysBase = *(struct ExecBase **) 4;
    struct Message *wbstartupmsg = 0;
    struct Process *self = (struct Process *) FindTask(0);
    if (self->pr_CLI == 0)
    {
    WaitPort(&self->pr_MsgPort);
    wbstartupmsg = GetMsg(&self->pr_MsgPort);
    }
    #else
    int main(void)
    {
    SysBase = *(struct ExecBase **) 4;
    #endif


    ... normal application code here ...


    #ifdef NOSTARTUPFILES
    if (wbstartupmsg)
    {
    Forbid();
    ReplyMsg(wbstartupmsg);
    }
    #endif
    return 0;
    }


    [ Edited by Piru 22.05.2014 - 19:15 ]
  • »22.05.14 - 11:45
    Profile