mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
picture: fix reloading images
Calling picture->load after it was already once called resulted in segmentation fault or memory leak (depending on whether the vector (svg, tvg) or raster (jpg, png, raw) file was loaded). This patch checks the image has already been loaded. If so, the load() returns InsufficientCondition. @issue: fixes #719
This commit is contained in:
parent
ca16e8b403
commit
399caaaff9
1 changed files with 6 additions and 3 deletions
|
@ -61,9 +61,9 @@ struct Picture::Impl
|
||||||
{
|
{
|
||||||
shared_ptr<LoadModule> loader = nullptr;
|
shared_ptr<LoadModule> loader = nullptr;
|
||||||
Paint* paint = nullptr;
|
Paint* paint = nullptr;
|
||||||
uint32_t *pixels = nullptr;
|
uint32_t* pixels = nullptr;
|
||||||
Picture *picture = nullptr;
|
Picture* picture = nullptr;
|
||||||
void *rdata = nullptr; //engine data
|
void* rdata = nullptr; //engine data
|
||||||
float w = 0, h = 0;
|
float w = 0, h = 0;
|
||||||
bool resizing = false;
|
bool resizing = false;
|
||||||
|
|
||||||
|
@ -184,6 +184,7 @@ struct Picture::Impl
|
||||||
|
|
||||||
Result load(const string& path)
|
Result load(const string& path)
|
||||||
{
|
{
|
||||||
|
if (paint || pixels) return Result::InsufficientCondition;
|
||||||
if (loader) loader->close();
|
if (loader) loader->close();
|
||||||
bool invalid; //Invalid Path
|
bool invalid; //Invalid Path
|
||||||
loader = LoaderMgr::loader(path, &invalid);
|
loader = LoaderMgr::loader(path, &invalid);
|
||||||
|
@ -199,6 +200,7 @@ struct Picture::Impl
|
||||||
|
|
||||||
Result load(const char* data, uint32_t size, const string& mimeType, bool copy)
|
Result load(const char* data, uint32_t size, const string& mimeType, bool copy)
|
||||||
{
|
{
|
||||||
|
if (paint || pixels) return Result::InsufficientCondition;
|
||||||
if (loader) loader->close();
|
if (loader) loader->close();
|
||||||
loader = LoaderMgr::loader(data, size, mimeType, copy);
|
loader = LoaderMgr::loader(data, size, mimeType, copy);
|
||||||
if (!loader) return Result::NonSupport;
|
if (!loader) return Result::NonSupport;
|
||||||
|
@ -210,6 +212,7 @@ struct Picture::Impl
|
||||||
|
|
||||||
Result load(uint32_t* data, uint32_t w, uint32_t h, bool copy)
|
Result load(uint32_t* data, uint32_t w, uint32_t h, bool copy)
|
||||||
{
|
{
|
||||||
|
if (paint || pixels) return Result::InsufficientCondition;
|
||||||
if (loader) loader->close();
|
if (loader) loader->close();
|
||||||
loader = LoaderMgr::loader(data, w, h, copy);
|
loader = LoaderMgr::loader(data, w, h, copy);
|
||||||
if (!loader) return Result::NonSupport;
|
if (!loader) return Result::NonSupport;
|
||||||
|
|
Loading…
Add table
Reference in a new issue