语言

Menu
Sites
Language
Double execution of get_text function in genlists

I am having problem with double execution of the text_get callback function for genlists.

If I have the following code in a button callback function to add an entry to genlist log_list


    char* entry_display;

...

    dlog_print(DLOG_DEBUG, LOG_TAG, "button clicked");

    Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
    itc->item_style = "type1";
    itc->func.text_get = _item_label_get;
    itc->func.content_get = NULL;
    itc->func.state_get = NULL;
    itc->func.del = NULL;

    elm_genlist_item_prepend(ad_change->log_list, itc,
            entry_display, NULL,ELM_GENLIST_ITEM_NONE, NULL, NULL);


and the _item_label_get function:

char *
_item_label_get(void *data, Evas_Object *obj, const char *part)
{
    char* this_item;

    this_item = data;
    dlog_print(DLOG_DEBUG, LOG_TAG, data);
    dlog_print(DLOG_DEBUG, LOG_TAG, part);

       if (!strcmp(part, "elm.text"))
       {
           return strdup(data);
       }

       else return NULL;
}

This is what I get from the device log:

D/APP_TAG ( 3207): button clicked
D/APP_TAG ( 3207): test
D/APP_TAG ( 3207): elm.text
D/APP_TAG ( 3207): test
D/APP_TAG ( 3207): elm.text.end
D/APP_TAG ( 3207): test
D/APP_TAG ( 3207): elm.text.sub
D/APP_TAG ( 3207): test
D/APP_TAG ( 3207): elm.text.sub.end
D/APP_TAG ( 3207): test
D/APP_TAG ( 3207): elm.text
D/APP_TAG ( 3207): test
D/APP_TAG ( 3207): elm.text.end
D/APP_TAG ( 3207): test
D/APP_TAG ( 3207): elm.text.sub
D/APP_TAG ( 3207): test
D/APP_TAG ( 3207): elm.text.sub.end

The function is apparently called twice for each element. This does not alter the behavior in this case but if I change the data pointer to the struct:

typedef struct{
    char* time;
    char* log_name;
}log_item;

And the debug logging to:

    dlog_print(DLOG_DEBUG, LOG_TAG, this_item->log_name);
    dlog_print(DLOG_DEBUG, LOG_TAG, this_item->time);

I get this in the device log:

D/APP_TAG ( 3257): button clicked
D/APP_TAG ( 3257): test2
D/APP_TAG ( 3257): 2016-01-20 08:51:42
D/APP_TAG ( 3257): test2
D/APP_TAG ( 3257): 2016-01-20 08:51:42
D/APP_TAG ( 3257): test2
D/APP_TAG ( 3257): 2016-01-20 08:51:42
D/APP_TAG ( 3257): test2
D/APP_TAG ( 3257): 2016-01-20 08:51:42
D/APP_TAG ( 3257): È7ַp¸۷ð}ݷðjܷ
D/APP_TAG ( 3257): ð}ݷðjܷ
D/APP_TAG ( 3257): È7ַð}ݷèVڷðjܷ
D/APP_TAG ( 3257): èVڷðjܷ
D/APP_TAG ( 3257): È7ַð}ݷèVڷðjܷ
D/APP_TAG ( 3257): èVڷðjܷ
D/APP_TAG ( 3257): È7ַð}ݷèVڷðjܷ
D/APP_TAG ( 3257): èVڷðjܷ

Obiously the genlist does not look pretty. This looks like undefined behavior am I missing something?

The application is compiled with 2.4 rev 2 sdk.

编辑者为: Henrik Ullman 20 1月, 2016

响应

2 回复
Hermet Park

genlist realization is non-determistic which means this behavior seems correct to me.

Because genlist needs to calculate it's items to decide actual item list in the viewport.

in the sequence it may realize/unrealize multiple times for the items for a decision.

Henrik Ullman

Ok, that also explains the garbage when I used implicit memory allocation for the struct as it gets freed efter the first function call. Explicit allocation with malloc solved it.