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 <collecting@noreply.localhost>
This commit is contained in:
Collecting
2025-11-03 03:05:28 +00:00
parent 424e4060bb
commit e097974a66

View File

@@ -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);