examples: ++exception handling

Added handling for engine initialization failure.
This commit is contained in:
Hermet Park 2024-07-14 11:58:00 +09:00 committed by Hermet Park
parent d42c10301e
commit 350f7a4357

View file

@ -122,8 +122,6 @@ struct Example
struct Window
{
static Window* instance;
SDL_Window* window = nullptr;
tvg::Canvas* canvas = nullptr;
@ -134,6 +132,7 @@ struct Window
bool needResize = false;
bool needDraw = false;
bool initialized = false;
bool print = false;
Window(tvg::CanvasEngine engine, Example* example, uint32_t width, uint32_t height, uint32_t threadsCnt)
@ -148,7 +147,7 @@ struct Window
this->width = width;
this->height = height;
this->example = example;
this->instance = this;
this->initialized = true;
}
virtual ~Window()
@ -254,8 +253,6 @@ struct Window
virtual void refresh() {}
};
Window* Window::instance = nullptr;
/************************************************************************/
/* SwCanvas Window Code */
@ -267,6 +264,8 @@ struct SwWindow : Window
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);
//Create a Canvas
@ -308,6 +307,8 @@ struct GlWindow : Window
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
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
@ -364,6 +365,8 @@ struct WgWindow : Window
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);
//Here we create our WebGPU surface from the window!