[APP] Flush log & save config on quick exit

This commit is contained in:
Adrian
2026-05-14 19:16:46 +01:00
committed by Radosław Gliński
parent 4c396fe611
commit a261b83def
5 changed files with 28 additions and 1 deletions

View File

@@ -574,6 +574,9 @@ void EmulatorApp::OnDestroy() {
// TODO(DrChat): Remove this code and do a proper exit.
XELOGI("Cheap-skate exit!");
xe::FlushLog();
std::quick_exit(EXIT_SUCCESS);
}

View File

@@ -65,6 +65,7 @@ DEFINE_int32(
namespace dp = disruptorplus;
using namespace xe::literals;
using namespace std::chrono_literals;
namespace xe {
@@ -240,9 +241,15 @@ class Logger {
sinks_.push_back(std::move(sink));
}
void FlushAllSinks() {
for (const auto& sink : sinks_) {
sink->Flush();
}
}
private:
static constexpr size_t kBufferSize = 8_MiB;
uint8_t buffer_[kBufferSize];
uint8_t buffer_[kBufferSize] = {};
static constexpr size_t kBlockSize = 256;
static constexpr size_t kBlockCount = kBufferSize / kBlockSize;
@@ -468,6 +475,15 @@ void ShutdownLogging() {
memory::AlignedFree(logger);
}
void FlushLog() {
if (!logger_) {
return;
}
xe::threading::Sleep(10ms);
logger_->FlushAllSinks();
}
static int g_saved_loglevel = static_cast<int>(LogLevel::Disabled);
void logging::ToggleLogLevel() {
auto swap = g_saved_loglevel;

View File

@@ -75,6 +75,7 @@ class DebugPrintLogSink final : public LogSink {
// Must be called on startup.
void InitializeLogging(const std::string_view app_name);
void ShutdownLogging();
void FlushLog();
namespace logging {

View File

@@ -286,6 +286,9 @@ void GraphicsSystem::OnHostGpuLossFromAnyThread(
if (host_gpu_loss_reported_.test_and_set(std::memory_order_relaxed)) {
return;
}
config::SaveConfig();
xe::FatalError("Graphics device lost (probably due to an internal error)");
}

View File

@@ -11,6 +11,7 @@
#include "xenia/base/cvar.h"
#include "xenia/base/logging.h"
#include "xenia/base/string_util.h"
#include "xenia/config.h"
#include "xenia/kernel/kernel_state.h"
#include "xenia/kernel/title_id_utils.h"
#include "xenia/kernel/user_module.h"
@@ -324,6 +325,9 @@ void XamLoaderLaunchTitle_entry(lpstring_t raw_name_ptr, dword_t flags) {
std::this_thread::yield();
}
config::SaveConfig();
xe::FlushLog();
std::quick_exit(0);
}).detach();
});