From bd8b0aec96ec43d3cf91a7b83625a12e50e0fc41 Mon Sep 17 00:00:00 2001 From: Jiga228 Date: Sun, 5 Oct 2025 14:28:39 +0700 Subject: [PATCH] Fix validate create instance --- Core/Core/CoreInstance.cpp | 14 +++++++++++--- Core/Core/CoreInstance.h | 5 ++++- Core/Core/main.cpp | 2 ++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Core/Core/CoreInstance.cpp b/Core/Core/CoreInstance.cpp index fdb8fe0..9f5ae64 100644 --- a/Core/Core/CoreInstance.cpp +++ b/Core/Core/CoreInstance.cpp @@ -71,10 +71,18 @@ CoreInstance::CoreInstance() } catch (const std::exception& e) { std::cout << "[!] Init render engine: " << e.what() << '\n'; - throw; + return; } - - game_ = GameFactory(*this); + + try + { + game_ = GameFactory(*this); + } catch (const std::exception& e) + { + std::cout << "[!] Init game instance: " << e.what() << '\n'; + return; + } + is_ready = true; } CoreInstance::~CoreInstance() diff --git a/Core/Core/CoreInstance.h b/Core/Core/CoreInstance.h index 43ee59f..fbd793c 100644 --- a/Core/Core/CoreInstance.h +++ b/Core/Core/CoreInstance.h @@ -47,6 +47,8 @@ class CoreInstance { static CoreInstance* self; CoreCallBacks callbacks_; + bool is_ready = false; + #pragma region Callbacks static void Quit_callback(); #pragma endregion @@ -56,7 +58,8 @@ public: void start(); void quit(); - + + bool IsReady() const { return is_ready; } int getCountCPU() const { return countCPU_; } double getMemorySize() const { return memorySize_; } const std::string& getBaseWorldName() const { return main_config_.base_world; } diff --git a/Core/Core/main.cpp b/Core/Core/main.cpp index e456cd3..3ac734d 100644 --- a/Core/Core/main.cpp +++ b/Core/Core/main.cpp @@ -5,6 +5,8 @@ int main(int argc, char* argv[]) { try { CoreInstance core; + if (core.IsReady() == false) + return 0; std::cout << "CPU: " << core.getCountCPU() << std::endl; std::cout << "Memory: " << core.getMemorySize() << std::endl; core.start();