lvgl / lv_lib_png

PNG decoder for LVGL
MIT License
66 stars 26 forks source link

memory allocation failed #2

Open simonchen007 opened 4 years ago

simonchen007 commented 4 years ago

hello,

I'm using esp32 + lvgl + lv_lib_lodepng, but when I use a png more 20K , it would shows "memory allocation failed", where can I change for making the memory allocation bigger ?

embeddedt commented 4 years ago

You probably have to increase LV_MEM_SIZE (or the size of whatever heap you use).

simonchen007 commented 4 years ago

I change it as (64U 1024U),still the same. however, I change it as 128U 1024U , I would goes to compile error.

kisvegabor commented 4 years ago

lodepng uses normal malloc. So you are simply out of heap on ESP.

simonchen007 commented 4 years ago

so, are you meaning the problem is because the esp32 having not enough money ? I tested over 50 times last night, if the PNG is over 5kb, I would get this error. however, if I use the normal way(make the png as c-array first), and do not use lodepng, 100kb png file is also works.

kisvegabor commented 4 years ago

so, are you meaning the problem is because the esp32 having not enough money ?

I don't know how much money ESP has but it might be out of memory. :slightly_smiling_face: :

The resolution of the PNG matters. During decoding the PNG image a hor. res x ver.res. x color size array is allocated into RAM. E.g. for 200 px x 200 px x 2 bytes = ~80kB

simonchen007 commented 4 years ago

esp32 having 320K memory. And I read the code of lodepng, "memory allocation failed" is because case 83 . if esp32 out of memory, I would not send any error, it would just go reboot.

kisvegabor commented 4 years ago

What is the resolution of the image?

simonchen007 commented 4 years ago

320*480

kisvegabor commented 4 years ago

It means the decompressed image is 3202402 = 300kB. If it uses 32-bit color format internally (I'm not sure now) than its 600 kB. Anyway, 320kB is not enough in either case.

simonchen007 commented 4 years ago

but why if I use the normal way(make the png as c-array first), and do not use lodepng, even 100kb png file is works ?

embeddedt commented 4 years ago

The PNG doesn't need to be decoded into RAM first with that method. It can be drawn directly from flash to the display.

rambo-panda commented 1 year ago

I also encountered the problem under lvgl 8.3. But I found two ways to solve it

  1. #LV_MEM_CUSTOM 1 use the malloc and free realloc
  2. convert to *.bin file

waiting for the real solution đŸ˜„

kisvegabor commented 1 year ago

You can increase LV_MEM_SIZE to add more memory for LVGL.

rambo-panda commented 1 year ago

Yes I tried, but it still reports an error。 So I personally think it's possible that lvgl's heap management may not be able to allocate large chunks of memory due to memory fragmentation in some cases

rambo-panda commented 1 year ago

@kisvegabor

apologize to you. it's my mistake.

I just committed git and found that the changelog had a change that I had debugged. It affected the lvgl allocation