examples: fix wrong data size conversion.

pointer size becomes 32 to 64 bits up to machines.
it has to be 32 bits.
This commit is contained in:
Hermet Park 2021-05-01 12:52:32 +09:00
parent 2bd07c050c
commit 6fce96a124
2 changed files with 6 additions and 10 deletions

View 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;
}

View 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();