example: Fix memory leak accepted/tizen/unified/20200615.135405 submit/tizen/20200611.221942 submit/tizen/20200614.220219
authorSubhransu Mohanty <smohantty@gmail.com>
Mon, 8 Jun 2020 02:07:59 +0000 (11:07 +0900)
committerJongmin Lee <jm105.lee@samsung.com>
Thu, 11 Jun 2020 22:01:29 +0000 (07:01 +0900)
example/demo_marker.cpp

index db74c32..68980c5 100644 (file)
 #include <sstream>
 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<LottieView>  view1;
+    std::unique_ptr<LottieView>  view2;
+    std::unique_ptr<LottieView>  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;