From e097974a66d1d710356e13518c3dc292ffa0b121 Mon Sep 17 00:00:00 2001 From: Collecting Date: Mon, 3 Nov 2025 03:05:28 +0000 Subject: [PATCH] fix: Race Condition when Updating UI/OS Theme Testing and fiddling with our recent overhaul for changing OS/UI themes and updating on the fly resulting in a segmentation fault that also would not allow you to re-open the emulator unless changing back to the theme previously known by Citron, which obviously we don't want. Grabbed the core dump. The backtrace pointed to a race condition in GMainWindow::UpdateUITheme, where a QTextStream was reading from a Qt resource stylesheet (.qss) that was being simultaneously reloaded by the theme change event. This led to an attempt to read from a dangling pointer. This change resolves the issue by reading the entire stylesheet into memory in a single, atomic operation using f.readAll(). This prevents the underlying resource from becoming invalid during the read. The resulting QByteArray is explicitly converted to a QString via QString::fromUtf8 to satisfy Qt 6's stricter type requirements. Signed-off-by: Collecting --- src/citron/main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/citron/main.cpp b/src/citron/main.cpp index a3808b5ff..971bc1855 100644 --- a/src/citron/main.cpp +++ b/src/citron/main.cpp @@ -5801,8 +5801,7 @@ void GMainWindow::UpdateUITheme() { QString theme_uri{QStringLiteral(":%1/style.qss").arg(current_theme)}; QFile f(theme_uri); if (f.open(QFile::ReadOnly | QFile::Text)) { - QTextStream ts(&f); - qApp->setStyleSheet(ts.readAll()); + qApp->setStyleSheet(QString::fromUtf8(f.readAll())); } else { LOG_ERROR(Frontend, "Unable to set style \"{}\", stylesheet file not found", UISettings::values.theme);