examples: ensure the file is closed

In case of an error during memory allocation
for file data, the file was not closed.
This commit is contained in:
Mira Grudzinska 2024-06-15 14:41:39 +02:00 committed by Hermet Park
parent 393fc88570
commit 7ec67baf9a

View file

@ -58,12 +58,12 @@ void tvgDrawCmds(tvg::Canvas* canvas)
auto size = file.tellg();
file.seekg(0, std::ios::beg);
auto data = (char*)malloc(size);
if (!data) return;
file.read(data, size);
file.close();
if (data && file.read(data, size)) {
if (tvg::Text::load("SentyCloud", data, size, "ttf", true) != tvg::Result::Success) {
cout << "Error while loading TTF from memory. Did you enable TTF Loader?" << endl;
}
}
file.close();
free(data);
auto text = tvg::Text::gen();