mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-15 04:24:28 +00:00
examples: ++exception handling
Added handling for engine initialization failure.
This commit is contained in:
parent
ea7f8e6190
commit
7e9febf2c6
1 changed files with 8 additions and 6 deletions
|
@ -122,8 +122,6 @@ struct Example
|
||||||
|
|
||||||
struct Window
|
struct Window
|
||||||
{
|
{
|
||||||
static Window* instance;
|
|
||||||
|
|
||||||
SDL_Window* window = nullptr;
|
SDL_Window* window = nullptr;
|
||||||
|
|
||||||
tvg::CanvasEngine engine;
|
tvg::CanvasEngine engine;
|
||||||
|
@ -135,6 +133,7 @@ struct Window
|
||||||
|
|
||||||
bool needResize = false;
|
bool needResize = false;
|
||||||
bool needDraw = false;
|
bool needDraw = false;
|
||||||
|
bool initialized = false;
|
||||||
bool print = false;
|
bool print = false;
|
||||||
|
|
||||||
Window(tvg::CanvasEngine engine, Example* example, uint32_t width, uint32_t height, uint32_t threadsCnt)
|
Window(tvg::CanvasEngine engine, Example* example, uint32_t width, uint32_t height, uint32_t threadsCnt)
|
||||||
|
@ -149,8 +148,7 @@ struct Window
|
||||||
this->width = width;
|
this->width = width;
|
||||||
this->height = height;
|
this->height = height;
|
||||||
this->example = example;
|
this->example = example;
|
||||||
this->engine = engine;
|
this->initialized = true;
|
||||||
this->instance = this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Window()
|
virtual ~Window()
|
||||||
|
@ -256,8 +254,6 @@ struct Window
|
||||||
virtual void refresh() {}
|
virtual void refresh() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
Window* Window::instance = nullptr;
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
/* SwCanvas Window Code */
|
/* SwCanvas Window Code */
|
||||||
|
@ -269,6 +265,8 @@ struct SwWindow : Window
|
||||||
|
|
||||||
SwWindow(Example* example, uint32_t width, uint32_t height, uint32_t threadsCnt) : Window(tvg::CanvasEngine::Sw, example, width, height, threadsCnt)
|
SwWindow(Example* example, uint32_t width, uint32_t height, uint32_t threadsCnt) : Window(tvg::CanvasEngine::Sw, example, width, height, threadsCnt)
|
||||||
{
|
{
|
||||||
|
if (!initialized) return;
|
||||||
|
|
||||||
window = SDL_CreateWindow("ThorVG Example (Software)", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE);
|
window = SDL_CreateWindow("ThorVG Example (Software)", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE);
|
||||||
|
|
||||||
//Create a Canvas
|
//Create a Canvas
|
||||||
|
@ -312,6 +310,8 @@ struct GlWindow : Window
|
||||||
|
|
||||||
GlWindow(Example* example, uint32_t width, uint32_t height, uint32_t threadsCnt) : Window(tvg::CanvasEngine::Gl, example, width, height, threadsCnt)
|
GlWindow(Example* example, uint32_t width, uint32_t height, uint32_t threadsCnt) : Window(tvg::CanvasEngine::Gl, example, width, height, threadsCnt)
|
||||||
{
|
{
|
||||||
|
if (!initialized) return;
|
||||||
|
|
||||||
#ifdef THORVG_GL_TARGET_GLES
|
#ifdef THORVG_GL_TARGET_GLES
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||||
|
@ -368,6 +368,8 @@ struct WgWindow : Window
|
||||||
|
|
||||||
WgWindow(Example* example, uint32_t width, uint32_t height, uint32_t threadsCnt) : Window(tvg::CanvasEngine::Wg, example, width, height, threadsCnt)
|
WgWindow(Example* example, uint32_t width, uint32_t height, uint32_t threadsCnt) : Window(tvg::CanvasEngine::Wg, example, width, height, threadsCnt)
|
||||||
{
|
{
|
||||||
|
if (!initialized) return;
|
||||||
|
|
||||||
window = SDL_CreateWindow("ThorVG Example (WebGPU)", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_HIDDEN);
|
window = SDL_CreateWindow("ThorVG Example (WebGPU)", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_HIDDEN);
|
||||||
|
|
||||||
//Here we create our WebGPU surface from the window!
|
//Here we create our WebGPU surface from the window!
|
||||||
|
|
Loading…
Add table
Reference in a new issue