Ignore:
Timestamp:
Feb 3, 2011, 10:39:34 AM (10 years ago)
Author:
sam
Message:

Add a safeguard mechanism that gets rid of stuck entities upon shutdown.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ticker.cpp

    r289 r342  
    3131        todolist(0), autolist(0),
    3232        nentities(0),
    33         frame(0), deltams(0), bias(0)
     33        frame(0), deltams(0), bias(0),
     34        quit(0), quitframe(0), quitdelay(20)
    3435    {
    3536        for (int i = 0; i < Entity::ALLGROUP_END; i++)
     
    6162
    6263    /* Fixed framerate management */
    63     int frame, quitframe;
     64    int frame;
    6465    Timer timer;
    6566    float deltams, bias;
     67
     68    /* Shutdown management */
     69    int quit, quitframe, quitdelay;
    6670}
    6771tickerdata;
     
    153157    data->bias += data->deltams;
    154158
     159    /* If shutdown is stuck, kick the first entity we meet and see
     160     * whether it makes things better. Note that it is always a bug to
     161     * have referenced entities after 20 frames, but at least this
     162     * safeguard makes it possible to exit the program cleanly. */
     163    if (data->quit && !((data->frame - data->quitframe) % data->quitdelay))
     164    {
     165        Entity *entity = NULL;
     166        for (int i = 0; i < Entity::ALLGROUP_END && !entity; i++)
     167            entity = data->list[i];
     168        if (entity && entity->ref)
     169        {
     170#if !FINAL_RELEASE
     171            fprintf(stderr, "ERROR: %i entities stuck after %i frames\n",
     172                    data->nentities, data->quitdelay);
     173#endif
     174            entity->ref--;
     175            data->quitdelay = data->quitdelay > 1 ? data->quitdelay / 2 : 1;
     176        }
     177    }
     178
    155179    /* Garbage collect objects that can be destroyed. We can do this
    156180     * before inserting awaiting objects, because only objects already in
     
    289313    }
    290314
     315    data->quit = 1;
    291316    data->quitframe = data->frame;
    292317}
Note: See TracChangeset for help on using the changeset viewer.