Skip to content

Commit

Permalink
Fix a bug when constructing a std::string from a ROString
Browse files Browse the repository at this point in the history
  • Loading branch information
X-Ryl669 committed Jan 26, 2022
1 parent 01ff48d commit c7915c6
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 7 deletions.
23 changes: 21 additions & 2 deletions example/lottieviewtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ class LottieViewTest
ecore_animator_frametime_set(1.0f/120.0f);
}

void show(const char * filepath) {
std::unique_ptr<LottieView> 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));

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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++;
Expand All @@ -148,14 +163,18 @@ 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++;
}
}

EvasApp *app = new EvasApp(800, 800);
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);

Expand Down
18 changes: 18 additions & 0 deletions inc/rlottiecommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lottie/JSON
Submodule JSON updated 2 files
+3 −2 JSON.hpp
+486 −0 ROString.hpp
9 changes: 7 additions & 2 deletions src/lottie/lottiemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lottie/lottieroparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand Down
8 changes: 7 additions & 1 deletion src/lottie/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

source_file = [
'lottieparser.cpp',
'lottieloader.cpp',
'lottiemodel.cpp',
'lottieproxymodel.cpp',
Expand All @@ -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
Expand Down

0 comments on commit c7915c6

Please sign in to comment.