mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
example: improved to print proper fail msgs.
This commit is contained in:
parent
e7c9ec790c
commit
300ced90c1
2 changed files with 12 additions and 13 deletions
|
@ -59,7 +59,7 @@ using namespace std;
|
|||
namespace tvgexam
|
||||
{
|
||||
|
||||
bool verify(tvg::Result result);
|
||||
bool verify(tvg::Result result, string failMsg = "");
|
||||
|
||||
struct Example
|
||||
{
|
||||
|
@ -140,10 +140,7 @@ struct Window
|
|||
Window(tvg::CanvasEngine engine, Example* example, uint32_t width, uint32_t height)
|
||||
{
|
||||
//Initialize ThorVG Engine (4: threads count, engine: raster method)
|
||||
if (!verify(tvg::Initializer::init(4, engine))) {
|
||||
cout << "Failed to init ThorVG engine!" << endl;
|
||||
return;
|
||||
}
|
||||
if (!verify(tvg::Initializer::init(4, engine), "Failed to init ThorVG engine!")) return;
|
||||
|
||||
//Initialize the SDL
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
|
@ -466,31 +463,31 @@ float progress(uint32_t elapsed, float durationInSec, bool rewind = false)
|
|||
}
|
||||
|
||||
|
||||
bool verify(tvg::Result result)
|
||||
bool verify(tvg::Result result, string failMsg)
|
||||
{
|
||||
switch (result) {
|
||||
case tvg::Result::FailedAllocation: {
|
||||
cout << "FailedAllocation!" << endl;
|
||||
cout << "FailedAllocation! " << failMsg << endl;
|
||||
return false;
|
||||
}
|
||||
case tvg::Result::InsufficientCondition: {
|
||||
cout << "InsufficientCondition!" << endl;
|
||||
cout << "InsufficientCondition! " << failMsg << endl;
|
||||
return false;
|
||||
}
|
||||
case tvg::Result::InvalidArguments: {
|
||||
cout << "InvalidArguments!" << endl;
|
||||
cout << "InvalidArguments! " << failMsg << endl;
|
||||
return false;
|
||||
}
|
||||
case tvg::Result::MemoryCorruption: {
|
||||
cout << "MemoryCorruption!" << endl;
|
||||
cout << "MemoryCorruption! " << failMsg << endl;
|
||||
return false;
|
||||
}
|
||||
case tvg::Result::NonSupport: {
|
||||
cout << "NonSupport!" << endl;
|
||||
cout << "NonSupport! " << failMsg << endl;
|
||||
return false;
|
||||
}
|
||||
case tvg::Result::Unknown: {
|
||||
cout << "Unknown!" << endl;
|
||||
cout << "Unknown! " << failMsg << endl;
|
||||
return false;
|
||||
}
|
||||
default: break;
|
||||
|
|
|
@ -34,7 +34,9 @@ struct UserExample : tvgexam::Example
|
|||
|
||||
//load the tvg file
|
||||
auto picture = tvg::Picture::gen();
|
||||
if (!tvgexam::verify(picture->load(EXAMPLE_DIR"/tvg/test.tvg"))) return false;
|
||||
if (!tvgexam::verify(picture->load(EXAMPLE_DIR"/tvg/test.tvg"), "You might need to run \"TvgSaver\" example first to generate the \"test.tvg\".")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
float w2, h2;
|
||||
picture->size(&w2, &h2);
|
||||
|
|
Loading…
Add table
Reference in a new issue