From 5e76c8a38252d8ae563a808672fed55645c8a765 Mon Sep 17 00:00:00 2001 From: illyum Date: Fri, 20 Sep 2024 10:45:08 -0600 Subject: [PATCH] chore(example)(client): update to work with latest engine changes - Change logging to explain the new fatal handler. - Add custom termination handler example --- examples/client/client.cpp | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/examples/client/client.cpp b/examples/client/client.cpp index 224e3bd..adcfbdd 100644 --- a/examples/client/client.cpp +++ b/examples/client/client.cpp @@ -4,20 +4,21 @@ #include #include +#include void ShowLogger(); +void CustomTermHandler(const std::string& message); int main() { - try { - ShowLogger(); - ICEngine::StartApplication(); - } catch (const std::exception& e) { - CORE_LOG_FATAL("Unhandled exception: {}", e.what()); - return -1; - } catch (...) { - CORE_LOG_FATAL("Unknown fatal error occurred."); - return -1; - } + // You can set a custom termination handler/function. + // Make sure you do this before you start the application!!! + ICEngine::ICEApplication::SetTerminationHandler(CustomTermHandler); + // This is optional + + // Logger Information + ShowLogger(); + + ICEngine::StartApplication(); return 0; } @@ -49,7 +50,10 @@ void ShowLogger() { // take ownership of the streams and clean them up when the app // is complete ICEngine::Log::GetCoreLogger()->AddSink(std::make_shared("core_logs.txt")); + ICEngine::Log::GetCoreLogger()->AddSink(std::make_shared()); + ICEngine::Log::GetAppLogger()->AddSink(std::make_shared("app_logs.txt")); + ICEngine::Log::GetAppLogger()->AddSink(std::make_shared()); // You can log multiple different types with formatting int age = 30; @@ -62,7 +66,7 @@ void ShowLogger() { CORE_LOG_DEBUG("This is an example of a debug message"); // Logs a debug message, typically used for debugging purposes CORE_LOG_WARN("This is an example of a warn message"); // Logs a warning, indicating a non-critical issue that should be investigated CORE_LOG_ERROR("This is an example of an error message"); // Logs an error, signaling that something has gone wrong but the engine can still run - CORE_LOG_CRITICAL("This is an example of a critical message\n"); // Logs a critical issue, often indicating a major problem in the core system that needs immediate attention. + CORE_LOG_CRITICAL("This is an example of a critical message"); // Logs a critical issue, often indicating a major problem in the core system that needs immediate attention. // CORE_LOG_FATAL: Logs a fatal error that crashes the application. Fatal errors in the core usually lead to dumping information into crash logs // and stopping the program. Use with extreme caution and only in situations where the application can't recover // CORE_LOG_FATAL("This is an example of a fatal message"); @@ -81,10 +85,21 @@ void ShowLogger() { // LOG_FATAL("This is an example of log fatal crash!"); } +void CustomTermHandler(const std::string& message) { + // Perform any other task here, like showing a popup warning indicating something crashed + Platform::ShowPopup("Demo App", message); + // You don't have to specify a title, it will default to ICEngine + // Platform::ShowPopup(message); + std::exit(EXIT_FAILURE); // Terminate here if you need to +} + + class DemoApp : public ICEngine::ICEApplication { public: void Run() override { LOG_TRACE("Running demo app!"); + CORE_LOG_FATAL("Fatal error"); // This will terminate the application + LOG_TRACE("Demo app completed successfully!"); // Therefore this will not run } };