From: subhransu mohanty Date: Mon, 4 Nov 2019 07:41:28 +0000 (+0900) Subject: fixed memory leak in demo application X-Git-Tag: submit/tizen/20191111.211104~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a15f15ac248ef3c094e71ac812a49e775b8e4d98;p=platform%2Fcore%2Fuifw%2Flottie-player.git fixed memory leak in demo application --- diff --git a/example/demo.cpp b/example/demo.cpp index 623f73e..c38da60 100644 --- a/example/demo.cpp +++ b/example/demo.cpp @@ -24,11 +24,92 @@ #include using namespace std; +class Demo +{ +public: + Demo(EvasApp *app, std::string &filePath) { + Demo1(app, filePath); + Demo2(app, filePath); + Demo3(app, filePath); + + } + void Demo1(EvasApp *app, std::string &filePath) { + /* Fill Color */ + view.reset(new LottieView(app->evas())); + view->setFilePath(filePath.c_str()); + if (view->player()) { + view->player()->setValue("Shape Layer 1.Ellipse 1.Fill 1", + [](const rlottie::FrameInfo& info) { + if (info.curFrame() < 60 ) + return rlottie::Color(0, 0, 1); + else { + return rlottie::Color(1, 0, 0); + } + }); + } + view->setPos(0, 0); + view->setSize(300, 300); + view->show(); + view->play(); + view->loop(true); + view->setRepeatMode(LottieView::RepeatMode::Reverse); + } + + void Demo2(EvasApp *app, std::string &filePath) { + /* Stroke Opacity */ + view1.reset(new LottieView(app->evas())); + view1->setFilePath(filePath.c_str()); + if (view1->player()) { + view1->player()->setValue("Shape Layer 2.Shape 1.Stroke 1", + [](const rlottie::FrameInfo& info) { + if (info.curFrame() < 60 ) + return 20; + else { + return 100; + } + }); + } + view1->setPos(300, 0); + view1->setSize(300, 300); + view1->show(); + view1->play(); + view1->loop(true); + view1->setRepeatMode(LottieView::RepeatMode::Reverse); + } + + void Demo3(EvasApp *app, std::string &filePath) { + /* Stroke Opacity */ + view2.reset(new LottieView(app->evas())); + view2->setFilePath(filePath.c_str()); + if (view2->player()) { + view2->player()->setValue("**", + [](const rlottie::FrameInfo& info) { + if (info.curFrame() < 60 ) + return 1.0; + else { + return 5.0; + } + }); + } + view2->setPos(600, 0); + view2->setSize(300, 300); + view2->show(); + view2->play(); + view2->loop(true); + view2->setRepeatMode(LottieView::RepeatMode::Reverse); + } + +private: + std::unique_ptr view; + std::unique_ptr view1; + std::unique_ptr view2; +}; + static void onExitCb(void *data, void */*extra*/) { - LottieView *view = (LottieView *)data; - delete view; + Demo *demo = (Demo *)data; + delete demo; } int @@ -40,68 +121,10 @@ main(void) std::string filePath = DEMO_DIR; filePath +="done.json"; - /* Fill Color */ - LottieView *view = new LottieView(app->evas()); - view->setFilePath(filePath.c_str()); - if (view->player()) { - view->player()->setValue("Shape Layer 1.Ellipse 1.Fill 1", - [](const rlottie::FrameInfo& info) { - if (info.curFrame() < 60 ) - return rlottie::Color(0, 0, 1); - else { - return rlottie::Color(1, 0, 0); - } - }); - } - view->setPos(0, 0); - view->setSize(300, 300); - view->show(); - view->play(); - view->loop(true); - view->setRepeatMode(LottieView::RepeatMode::Reverse); - - - /* Stroke Opacity */ - view = new LottieView(app->evas()); - view->setFilePath(filePath.c_str()); - if (view->player()) { - view->player()->setValue("Shape Layer 2.Shape 1.Stroke 1", - [](const rlottie::FrameInfo& info) { - if (info.curFrame() < 60 ) - return 20; - else { - return 100; - } - }); - } - view->setPos(300, 0); - view->setSize(300, 300); - view->show(); - view->play(); - view->loop(true); - view->setRepeatMode(LottieView::RepeatMode::Reverse); - - /* Stroke Width and Globstar path (All Content) */ - view = new LottieView(app->evas()); - view->setFilePath(filePath.c_str()); - if (view->player()) { - view->player()->setValue("**", - [](const rlottie::FrameInfo& info) { - if (info.curFrame() < 60 ) - return 1.0; - else { - return 5.0; - } - }); - } - view->setPos(600, 0); - view->setSize(300, 300); - view->show(); - view->play(); - view->loop(true); - view->setRepeatMode(LottieView::RepeatMode::Reverse); - app->addExitCb(onExitCb, view); - app->run(); + auto demo = new Demo(app, filePath); + + app->addExitCb(onExitCb, demo); + app->run(); delete app; return 0;