examples: fix wrong data size conversion.
authorHermet Park <chuneon.park@samsung.com>
Sat, 1 May 2021 03:52:32 +0000 (12:52 +0900)
committerHermet Park <chuneon.park@samsung.com>
Mon, 10 May 2021 04:56:31 +0000 (13:56 +0900)
pointer size becomes 32 to 64 bits up to machines.
it has to be 32 bits.

src/examples/Masking.cpp
src/examples/PictureRaw.cpp

index 6140a2b..4112d99 100644 (file)
@@ -27,8 +27,6 @@
 /* Drawing Commands                                                     */
 /************************************************************************/
 
-uint32_t *data = nullptr;
-
 void tvgDrawCmds(tvg::Canvas* canvas)
 {
     if (!canvas) return;
@@ -87,8 +85,8 @@ void tvgDrawCmds(tvg::Canvas* canvas)
     //Image
     ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw");
     if (!file.is_open()) return;
-    data = (uint32_t*) malloc(sizeof(uint32_t) * (200 * 300));
-    file.read(reinterpret_cast<char *>(data), sizeof (data) * 200 * 300);
+    auto data = (uint32_t*) malloc(sizeof(uint32_t) * (200 * 300));
+    file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);
     file.close();
 
     auto image = tvg::Picture::gen();
@@ -111,6 +109,8 @@ void tvgDrawCmds(tvg::Canvas* canvas)
     mask4->fill(255, 255, 255, 70);
     image->composite(move(mask4), tvg::CompositeMethod::AlphaMask);
     if (canvas->push(move(image)) != tvg::Result::Success) return;
+
+    free(data);
 }
 
 
@@ -214,8 +214,6 @@ int main(int argc, char **argv)
         //Terminate ThorVG Engine
         tvg::Initializer::term(tvg::CanvasEngine::Sw);
 
-        if (data) free(data);
-
     } else {
         cout << "engine is not supported" << endl;
     }
index e65087a..8575e4f 100644 (file)
@@ -27,8 +27,6 @@
 /* Drawing Commands                                                     */
 /************************************************************************/
 
-uint32_t *data = nullptr;
-
 void tvgDrawCmds(tvg::Canvas* canvas)
 {
     if (!canvas) return;
@@ -44,8 +42,8 @@ void tvgDrawCmds(tvg::Canvas* canvas)
 
     ifstream file(path);
     if (!file.is_open()) return ;
-    data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300));
-    file.read(reinterpret_cast<char *>(data), sizeof (data) * 200 * 300);
+    auto data = (uint32_t*)malloc(sizeof(uint32_t) * (200*300));
+    file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);
     file.close();
 
     auto picture = tvg::Picture::gen();