Skip to content

Commit

Permalink
example: Fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
smohantty committed Jun 8, 2020
1 parent 607998b commit adcc5f0
Showing 1 changed file with 42 additions and 29 deletions.
71 changes: 42 additions & 29 deletions example/demo_marker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,48 @@
#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
Expand All @@ -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;
Expand Down

0 comments on commit adcc5f0

Please sign in to comment.