From bca45488d10b690f916bf9f9cab0bdc6bb073023 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Sun, 21 Jul 2024 23:18:13 +0200 Subject: [PATCH] Encapsulate Main#run logic in try-catch block --- .../sosengine/graphics/package-info.java | 34 ++++++----- .../sosengine/testapp/Main.java | 59 ++++++++++--------- 2 files changed, 50 insertions(+), 43 deletions(-) diff --git a/graphics/src/main/java/de/staropensource/sosengine/graphics/package-info.java b/graphics/src/main/java/de/staropensource/sosengine/graphics/package-info.java index ddced00..6015dcc 100644 --- a/graphics/src/main/java/de/staropensource/sosengine/graphics/package-info.java +++ b/graphics/src/main/java/de/staropensource/sosengine/graphics/package-info.java @@ -1,23 +1,25 @@ /* - STAROPENSOURCE ENGINE SOURCE FILE - Copyright (c) 2024 The StarOpenSource Engine Contributors - Licensed under the GNU Affero General Public License v3 - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * Licensed under the GNU Affero General Public License v3 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ /** * Contains the code required for drawing things to a screen. + * + * @since v1-alpha0 */ package de.staropensource.sosengine.graphics; diff --git a/testapp/src/main/java/de/staropensource/sosengine/testapp/Main.java b/testapp/src/main/java/de/staropensource/sosengine/testapp/Main.java index 549c775..a01f09f 100644 --- a/testapp/src/main/java/de/staropensource/sosengine/testapp/Main.java +++ b/testapp/src/main/java/de/staropensource/sosengine/testapp/Main.java @@ -96,35 +96,40 @@ public class Main { */ @SneakyThrows public void run(String[] args) { - // Initialize sos!engine - engine = new Engine(); - - // Say hello to the world! - logger.info("Hello world!"); - - // Choose Graphics API to use - if (!GraphicsSubsystem.getInstance().setGraphicsApi()) - logger.crash("No Graphics API is compatible"); - - // Define 'api' & 'management' variables - ApiMainClass api = GraphicsSubsystem.getInstance().getApi(); - ApiManagementClass management = api.getManagement(); - - // Create window try { - Window window = new Window.Builder() - .setTitle("test application window") - .setSize(new Vec2i(960, 540)) - .setPosition(new Vec2i(10, 10)) - .build(); + // Initialize sos!engine + engine = new Engine(); + + // Say hello to the world! + logger.info("Hello world!"); + + // Choose Graphics API to use + if (!GraphicsSubsystem.getInstance().setGraphicsApi()) + logger.crash("No Graphics API is compatible"); + + // Define 'api' & 'management' variables + ApiMainClass api = GraphicsSubsystem.getInstance().getApi(); + ApiManagementClass management = api.getManagement(); + + // Create window + try { + Window window = new Window.Builder() + .setTitle("test application window") + .setSize(new Vec2i(960, 540)) + .setPosition(new Vec2i(10, 10)) + .build(); + } catch (Throwable throwable) { + logger.crash("Window.Builder#build() failed", throwable); + } + + // Sleep for five seconds + Thread.sleep(5000); + + // Shutdown + Engine.getInstance().shutdown(0); } catch (Throwable throwable) { - logger.crash("Window.Builder#build() failed", throwable); + Thread.ofVirtual().start(() -> Engine.getInstance().shutdown(69)); + throw throwable; } - - // Sleep for five seconds - Thread.sleep(5000); - - // Shutdown - Engine.getInstance().shutdown(0); } }