False detection of a new image source


In function lv_img_set_src(), when the image source to set is a file or a symbol, a test to detect a new source for the image object is made by comparison between the source pointer and a pointer stored in the ext structure of the image (lv_img.c:190). This one points to an area of ​​the lvgl memory, allocated by the lv_mem_alloc() function, where is copied the string path of the file/symbol source (lv_img.c:198-202).

The comparaison made on line 190 is always true although the source image is the same because pointers never have same value : one points to a LVGL memory area, the other to a string (in program memory in my case). The good way is to compare pointed areas and not pointers values .

I suggest instead of if(ext->src != src_img) { writing something like if ((ext->src == NULL) || (memcmp(ext->src, src_img, strlen(src_img)) != 0)) {

Testing if ext->src is null is for the case of the first image source setting as memcpm(NULL,…) will crash.

What MCU/Processor/Board and compiler are you using?

Microsoft Visual Studio Community 2019 Version 16.6.5 for simulation

What do you experience?

The issue is not really critical as it just generates unnecessary image cache refresh in case of frequently setting the same file image source to an image widget.


Thanks for reporting it.

Can you send a Pull request with the suggested updates?