From c7915c6ade01737d4b9b296998ebbe8ad4d634aa Mon Sep 17 00:00:00 2001 From: X-Ryl669 Date: Wed, 26 Jan 2022 18:15:46 +0100 Subject: [PATCH] Fix a bug when constructing a std::string from a ROString --- example/lottieviewtest.cpp | 23 +++++++++++++++++++++-- inc/rlottiecommon.h | 18 ++++++++++++++++++ src/lottie/JSON | 2 +- src/lottie/lottiemodel.h | 9 +++++++-- src/lottie/lottieroparser.cpp | 2 +- src/lottie/meson.build | 8 +++++++- 6 files changed, 55 insertions(+), 7 deletions(-) diff --git a/example/lottieviewtest.cpp b/example/lottieviewtest.cpp index 402fcd27..fc775c6c 100644 --- a/example/lottieviewtest.cpp +++ b/example/lottieviewtest.cpp @@ -53,6 +53,19 @@ class LottieViewTest ecore_animator_frametime_set(1.0f/120.0f); } + void show(const char * filepath) { + std::unique_ptr view(new LottieView(mApp->evas(), mStrategy)); + view->setFilePath(filepath); + view->setPos(3, 3); + int vw = mApp->width() - 6; + view->setSize(vw, vw); + view->show(); + view->play(); + view->loop(true); + mViews.push_back(std::move(view)); + } + + void show(int numberOfImage) { auto resource = EvasApp::jsonFiles(std::string(DEMO_DIR)); @@ -92,9 +105,10 @@ class LottieViewTest } static int help() { - printf("Usage ./lottieviewTest [-s] [strategy] [-t] [timeout] [-c] [count]\n"); + printf("Usage ./lottieviewTest [-s] [strategy] [-t] [timeout] [-c] [count] [-f] path\n"); printf("\n \t-t : timeout duration in seconds\n"); printf("\n \t-c : number of resource in the grid\n"); + printf("\n \t-f : File to play\n"); printf("\n \t-s : Rendering Strategy\n"); printf("\t\t 0 - Test Lottie SYNC Renderer with CPP API\n"); printf("\t\t 1 - Test Lottie ASYNC Renderer with CPP API\n"); @@ -134,6 +148,7 @@ main(int argc, char **argv) auto index = 0; double timeOut = 0; size_t itemCount = 250; + std::string filePath; while (index < argc) { const char* option = argv[index]; index++; @@ -148,6 +163,9 @@ main(int argc, char **argv) } else if (!strcmp(option,"-c")) { itemCount = (index < argc) ? atoi(argv[index]) : 10; index++; + } else if (!strcmp(option,"-f")) { + filePath = argv[index]; + index++; } } @@ -155,7 +173,8 @@ main(int argc, char **argv) app->setup(); LottieViewTest *view = new LottieViewTest(app, st, timeOut); - view->show(itemCount); + if (filePath.length()) view->show(filePath.c_str()); + else view->show(itemCount); app->addExitCb(onExitCb, view); diff --git a/inc/rlottiecommon.h b/inc/rlottiecommon.h index 784fbe28..13525324 100644 --- a/inc/rlottiecommon.h +++ b/inc/rlottiecommon.h @@ -37,6 +37,24 @@ #endif #endif +#if defined LOTTIE_JSON_SUPPORT + #define RLOTTIE_FEATURE_RO_JSON 1 +#else + #define RLOTTIE_FEATURE_RO_JSON 0 +#endif + +#if defined LOTTIE_THREAD_SUPPORT + #define RLOTTIE_FEATURE_THREAD 1 +#else + #define RLOTTIE_FEATURE_THREAD 0 +#endif + +#if defined LOTTIE_NO_PARTIAL_RENDER + #define RLOTTIE_FEATURE_PARTIAL_RENDER 0 +#else + #define RLOTTIE_FEATURE_PARTIAL_RENDER 1 +#endif + /** * @defgroup Lottie_Animation Lottie_Animation diff --git a/src/lottie/JSON b/src/lottie/JSON index d9806adc..d9b64a9f 160000 --- a/src/lottie/JSON +++ b/src/lottie/JSON @@ -1 +1 @@ -Subproject commit d9806adc73663c38e1d855d722621938f957e841 +Subproject commit d9b64a9f6dda68f7da5e7fb8dedf173bdf0a8440 diff --git a/src/lottie/lottiemodel.h b/src/lottie/lottiemodel.h index b5751013..6530af88 100644 --- a/src/lottie/lottiemodel.h +++ b/src/lottie/lottiemodel.h @@ -475,10 +475,15 @@ class Object { if (name) { if (len < maxShortStringLength) { setShortString(true); - strncpy(mData._buffer, name, len + 1); + memcpy(mData._buffer, name, len); + mData._buffer[len] = 0; } else { setShortString(false); - mPtr = strdup(name); + mPtr = (char*)malloc(len+1); + if (mPtr) { + memcpy(mPtr, name, len); + mPtr[len] = 0; + } } } } diff --git a/src/lottie/lottieroparser.cpp b/src/lottie/lottieroparser.cpp index 008c133f..88731fdc 100644 --- a/src/lottie/lottieroparser.cpp +++ b/src/lottie/lottieroparser.cpp @@ -490,7 +490,7 @@ std::string LottieParserImpl::GetStringObject() ROString str = GetString(); if (str) { - return std::string(str, str.getLength()); + return std::string(str.getData(), str.getLength()); } return {}; diff --git a/src/lottie/meson.build b/src/lottie/meson.build index fcf8239c..1df3b82e 100644 --- a/src/lottie/meson.build +++ b/src/lottie/meson.build @@ -1,6 +1,5 @@ source_file = [ - 'lottieparser.cpp', 'lottieloader.cpp', 'lottiemodel.cpp', 'lottieproxymodel.cpp', @@ -10,6 +9,13 @@ source_file = [ 'lottiekeypath.cpp' ] +if get_option('json') + source_file += ['lottieroparser.cpp'] +else + source_file += ['lottieparser.cpp'] +endif + + lottie_dep = declare_dependency( include_directories : include_directories('.'), sources : source_file