From: Subhransu Mohanty Date: Mon, 8 Jun 2020 02:07:59 +0000 (+0900) Subject: example: Fix memory leak X-Git-Tag: submit/tizen/20200611.221942^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a036e280ff38aa11c54dba5c9defbcc646eec314;p=platform%2Fcore%2Fuifw%2Flottie-player.git example: Fix memory leak --- diff --git a/example/demo_marker.cpp b/example/demo_marker.cpp index db74c32..68980c5 100644 --- a/example/demo_marker.cpp +++ b/example/demo_marker.cpp @@ -24,11 +24,48 @@ #include using namespace std; +class DemoMarker +{ +public: + DemoMarker(EvasApp *app, std::string filePath) { + view1.reset(new LottieView(app->evas())); + view1->setFilePath(filePath.c_str()); + view1->setPos(0, 0); + view1->setSize(400, 400); + view1->show(); + view1->play(); + view1->loop(true); + + /* Play with marker */ + view2.reset(new LottieView(app->evas())); + view2->setFilePath(filePath.c_str()); + view2->setPos(400, 0); + view2->setSize(400, 400); + view2->show(); + view2->play("second"); + view2->loop(true); + + /* Play marker to marker */ + view3.reset(new LottieView(app->evas())); + view3->setFilePath(filePath.c_str()); + view3->setPos(800, 0); + view3->setSize(400, 400); + view3->show(); + view3->play("second", "third"); + view3->loop(true); + } + +private: + std::unique_ptr view1; + std::unique_ptr view2; + std::unique_ptr view3; +}; + static void onExitCb(void *data, void */*extra*/) { - LottieView *view = (LottieView *)data; - delete view; + DemoMarker *demo = (DemoMarker *)data; + delete demo; } int @@ -40,33 +77,9 @@ main(void) std::string filePath = DEMO_DIR; filePath +="marker.json"; - LottieView *view = new LottieView(app->evas()); - view->setFilePath(filePath.c_str()); - view->setPos(0, 0); - view->setSize(400, 400); - view->show(); - view->play(); - view->loop(true); - - /* Play with marker */ - view = new LottieView(app->evas()); - view->setFilePath(filePath.c_str()); - view->setPos(400, 0); - view->setSize(400, 400); - view->show(); - view->play("second"); - view->loop(true); - - /* Play marker to marker */ - view = new LottieView(app->evas()); - view->setFilePath(filePath.c_str()); - view->setPos(800, 0); - view->setSize(400, 400); - view->show(); - view->play("second", "third"); - view->loop(true); - - app->addExitCb(onExitCb, view); + auto demo = new DemoMarker(app, filePath); + + app->addExitCb(onExitCb, demo); app->run(); delete app;