0

I am creating a photo application which will show new photos (online) every x-seconds. But the application is crashing after some time at random moments. Created a test application (note: ugly/dirty and not optimized code) to reproduce the crashes, see code below.

#include <Elementary.h>
// gcc -g main.c -o main `pkg-config --cflags --libs elementary`

// @url https://www.enlightenment.org/docs/efl/start
Evas_Object *win;
int curIndex = 0;
int numposters = 1022;
int showXImages = 4;
int showYImages = 2;
int widthImage = 200;
int heightImage = 300;
int padding = 20;
Evas_Object* curImages[8] = {NULL}; // showXImages * showYImages

static void getImage(Evas_Object *win) {
    int x, y;
    for (y=0; y<showYImages; ++y) {
        for (x=0; x<showXImages; ++x) {
            // Destroy previous one
            int index = y*showXImages + x;
            if (curImages[index] != NULL) {
                evas_object_del(curImages[index]);
                curImages[index] = NULL;
            }

            // Create new image url
            char result[1024] = "";
            sprintf(result, "http://unsplash.it/200/300?image=%d", curIndex + index);

            // Add new image
            Evas_Object* img = elm_image_add(win);
            elm_image_file_set(img, result, NULL);
            evas_object_move(img, x * (widthImage + padding), y * (heightImage + padding));
            evas_object_resize(img, widthImage, heightImage);
            evas_object_show(img);

            // Set image
            curImages[index] = img;
        }
    }
}

Eina_Bool sCheckCallback(void *data) {
    // Increase index
    curIndex = curIndex + (showYImages*showXImages);
    curIndex = curIndex % numposters;

    // Get and set new images
    getImage(win);

    return ECORE_CALLBACK_RENEW;
}

EAPI_MAIN int elm_main(int argc, char **argv) {
    // Create window
    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
    win = elm_win_util_standard_add("Main", "Hello, World!");
    elm_win_autodel_set(win, EINA_TRUE);
    evas_object_resize(win, 1280, 720);
    evas_object_show(win);

    // Add callback
    Ecore_Timer* timer = ecore_timer_add(1.0f, sCheckCallback, NULL);

    elm_run();

    return 0;
}
ELM_MAIN()

To check if it was not just in efl 17.1, I also updated to efl-1.19.0-beta2 but there the crashes are still present. See also 1,2,3 for some screenshot(s) of the stacktrace.

user2276975
  • 69
  • 2
  • 9

1 Answers1

0

It looks a little like memory is getting leaked. My first thought would be to set up the elm_image grid on load of the application - then you can just call the elm_image_file_set which is far more efficient than destroyig and recreating the widgets.

I changed that here and the app seemed to run for much longer...

andy.xyz
  • 2,567
  • 1
  • 13
  • 18