mirror of
https://git.citron-emu.org/citron/emulator
synced 2025-12-30 15:04:07 +00:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user