chore(example)(client): update to work with latest engine changes

- Change logging to explain the new fatal handler.
- Add custom termination handler example
This commit is contained in:
illyum 2024-09-20 10:45:08 -06:00
parent 91cf0d25d5
commit 5e76c8a382

View File

@ -4,20 +4,21 @@
#include <ICEngine.hpp>
#include <fstream>
#include <src/platform/Platform.hpp>
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<ICEngine::FileSink>("core_logs.txt"));
ICEngine::Log::GetCoreLogger()->AddSink(std::make_shared<ICEngine::ConsoleSink>());
ICEngine::Log::GetAppLogger()->AddSink(std::make_shared<ICEngine::FileSink>("app_logs.txt"));
ICEngine::Log::GetAppLogger()->AddSink(std::make_shared<ICEngine::ConsoleSink>());
// 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
}
};