0

我正在创建一个照片应用程序,它将每隔 x 秒显示一次新照片(在线)。但是应用程序在随机时刻一段时间后崩溃。创建了一个测试应用程序(注意:丑陋/肮脏且未优化的代码)来重现崩溃,请参见下面的代码。

#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()

为了检查它是否不仅在 efl 17.1 中,我还更新到 efl-1.19.0-beta2 但崩溃仍然存在。有关堆栈跟踪的一些屏幕截图,另请参见123

4

1 回答 1

0

它看起来有点像内存泄漏。我的第一个想法是在加载应用程序时设置 elm_image 网格 - 然后您可以调用 elm_image_file_set,这比 destroyig 和重新创建小部件更有效。

我在这里改变了它,应用程序似乎运行了更长的时间......

于 2017-03-12T14:13:45.253 回答