LIST how to delete an Item

Hi to all…

I’ve a big problem … I can create a list, I can add Item … but It crash if I try to delete an Item …

Can Anyone hel me :slight_smile:


I’ve declared

static wm_lst_t database;
static s16 indice;

in then main
database = wm_lstCreate (WM_LIST_NONE, NULL);

and I fill then list
indice = wm_lstAddItem ( database, p_data );

in other section I try to Delete with

n= wm_lstDeleteItem ( database, indice );


How is your p_data defined?

The way the list is defined in your example, you are using the default clean up operation (which pretty much maps to adl_memFree()) to clean up when the list item is deleted.

If your p_data is a structure with pointers in it, then you will have to write your own clean up function to release the pointer memory before releasing the list element memory.

Also, make sure you aren’t adding automatic (i.e. local) variable to the list, as these will have gone out of scope once the function has returned and you will get an ARM exception when you try to delete them from the list.

An Example:

static wm_lst_t database;

    database = wm_lstCreate (WM_LIST_NONE, NULL);

void listInsert()
    s32 value;
    s32 *p_value;
    s32 index;

 // this is wrong, and will cause an exception when you try to access/delete the list item
    index = wm_lstAddItem(database, &value); 

// this works, as memory is allocated off the heap and remains accessable everywhere in your app
    p_value = adl_memGet(sizeof(s32));
    index = wm_lstAddItem(database, p_value); 

Hope this helps.

ciao, Dave