stolk / GPGOAP

General Purpose Goal Oriented Action Planning
558 stars 63 forks source link

goap_actionplanner_clear doesn't necessarily clear all actions #6

Closed ghost closed 9 years ago

ghost commented 9 years ago
typedef struct
{
    const char* atm_names[ MAXATOMS ];  //!< Names associated with all world state atoms.
    int numatoms;               //!< Number of world state atoms.

    const char* act_names[ MAXACTIONS ];    //!< Names of all actions in repertoire.
    worldstate_t act_pre[ MAXACTIONS ]; //!< Preconditions for all actions.
    worldstate_t act_pst[ MAXACTIONS ]; //!< Postconditions for all actions (action effects).
    int act_costs[ MAXACTIONS ];        //!< Cost for all actions.
    int numactions;             //!< The number of actions in out repertoire.

} actionplanner_t;

void goap_actionplanner_clear( actionplanner_t* ap )
{
    ap->numatoms = 0;
    ap->numactions = 0;
    for ( int i=0; i<MAXATOMS; ++i ) 
    {
        ap->atm_names[ i ] = 0;
        ap->act_names[ i ] = 0;
        ap->act_costs[ i ] = 0;
        goap_worldstate_clear( ap->act_pre+i );
        goap_worldstate_clear( ap->act_pst+i );
    }
}

const char* act_names[ MAXACTIONS ]; yet the loop only clears for for ( int i=0; i<MAXATOMS; ++i )

Although in your example MAXACTIONS==MAXATOMS, maybe this would not always be the case. I hope this is useful. Thank you for your time.

stolk commented 9 years ago

Thank you for reporting. Fixed in master branch.