mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
loader: code refactoring
Ensure scene data is freed when it's dangled in the loader.
This commit is contained in:
parent
9958d346cf
commit
0eafcfd1b0
4 changed files with 13 additions and 12 deletions
|
@ -284,10 +284,8 @@ bool LottieLoader::read()
|
|||
{
|
||||
if (!content || size == 0) return false;
|
||||
|
||||
if (!LoadModule::read()) return true;
|
||||
|
||||
//the loading has been already completed in header()
|
||||
if (comp) return true;
|
||||
//the loading has been already completed
|
||||
if (comp || !LoadModule::read()) return true;
|
||||
|
||||
TaskScheduler::request(this);
|
||||
|
||||
|
|
|
@ -3732,10 +3732,8 @@ bool SvgLoader::read()
|
|||
{
|
||||
if (!content || size == 0) return false;
|
||||
|
||||
if (!LoadModule::read()) return true;
|
||||
|
||||
//the loading has been already completed in header()
|
||||
if (root) return true;
|
||||
if (root || !LoadModule::read()) return true;
|
||||
|
||||
TaskScheduler::request(this);
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
/************************************************************************/
|
||||
|
||||
|
||||
void TvgLoader::clear()
|
||||
void TvgLoader::clear(bool all)
|
||||
{
|
||||
if (copy) free((char*)data);
|
||||
ptr = data = nullptr;
|
||||
|
@ -41,6 +41,8 @@ void TvgLoader::clear()
|
|||
|
||||
delete(interpreter);
|
||||
interpreter = nullptr;
|
||||
|
||||
if (all) delete(root);
|
||||
}
|
||||
|
||||
|
||||
|
@ -113,7 +115,7 @@ void TvgLoader::run(unsigned tid)
|
|||
root = interpreter->run(data, this->data + size);
|
||||
}
|
||||
|
||||
clear();
|
||||
clear(false);
|
||||
}
|
||||
|
||||
|
||||
|
@ -213,7 +215,8 @@ bool TvgLoader::read()
|
|||
{
|
||||
if (!ptr || size == 0) return false;
|
||||
|
||||
if (!LoadModule::read()) return true;
|
||||
//the loading has been already completed
|
||||
if (root || !LoadModule::read()) return true;
|
||||
|
||||
TaskScheduler::request(this);
|
||||
|
||||
|
@ -224,5 +227,7 @@ bool TvgLoader::read()
|
|||
Paint* TvgLoader::paint()
|
||||
{
|
||||
this->done();
|
||||
return root;
|
||||
auto ret = root;
|
||||
root = nullptr;
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
private:
|
||||
bool readHeader();
|
||||
void run(unsigned tid) override;
|
||||
void clear();
|
||||
void clear(bool all = true);
|
||||
};
|
||||
|
||||
#endif //_TVG_TVG_LOADER_H_
|
||||
|
|
Loading…
Add table
Reference in a new issue