mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-25 07:39:02 +00:00
common picture: ++exception case.
Fixed load() to return InvalidArgument if the file path is invalid.
This commit is contained in:
parent
113ca8b845
commit
8aa941c4ab
4 changed files with 12 additions and 5 deletions
|
@ -988,7 +988,7 @@ public:
|
|||
* @param[in] path A path to the picture file.
|
||||
*
|
||||
* @retval Result::Success When succeed.
|
||||
* @retval Result::InvalidArguments In case the @p path is empty.
|
||||
* @retval Result::InvalidArguments In case the @p path is invalid.
|
||||
* @retval Result::NonSupport When trying to load a file with an unknown extension.
|
||||
* @retval Result::Unknown If an error occurs at a later stage.
|
||||
*
|
||||
|
|
|
@ -131,11 +131,14 @@ bool LoaderMgr::term()
|
|||
}
|
||||
|
||||
|
||||
shared_ptr<Loader> LoaderMgr::loader(const string& path)
|
||||
shared_ptr<Loader> LoaderMgr::loader(const string& path, bool* invalid)
|
||||
{
|
||||
*invalid = false;
|
||||
|
||||
if (auto loader = _find(path)) {
|
||||
if (loader->open(path)) return shared_ptr<Loader>(loader);
|
||||
else delete(loader);
|
||||
*invalid = true;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ struct LoaderMgr
|
|||
{
|
||||
static bool init();
|
||||
static bool term();
|
||||
static shared_ptr<Loader> loader(const string& path);
|
||||
static shared_ptr<Loader> loader(const string& path, bool* invalid);
|
||||
static shared_ptr<Loader> loader(const char* data, uint32_t size, bool copy);
|
||||
static shared_ptr<Loader> loader(const uint32_t* data, uint32_t w, uint32_t h, bool copy);
|
||||
};
|
||||
|
|
|
@ -167,8 +167,12 @@ struct Picture::Impl
|
|||
Result load(const string& path)
|
||||
{
|
||||
if (loader) loader->close();
|
||||
loader = LoaderMgr::loader(path);
|
||||
if (!loader) return Result::NonSupport;
|
||||
bool invalid; //Invalid Path
|
||||
loader = LoaderMgr::loader(path, &invalid);
|
||||
if (!loader) {
|
||||
if (invalid) return Result::InvalidArguments;
|
||||
return Result::NonSupport;
|
||||
}
|
||||
if (!loader->read()) return Result::Unknown;
|
||||
w = loader->w;
|
||||
h = loader->h;
|
||||
|
|
Loading…
Add table
Reference in a new issue