From 20d3f0971cb96cb03e653e5f3e3d1e02d14d89fe Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 6 Jul 2022 01:25:39 +0600 Subject: [PATCH] Use atomic_bool instead of atomic_flag for doresizes atomic_flag seems to be broken on Windows for clearing them outside the thread they were tested and set in --- src/86box.c | 2 +- src/include/86box/video.h | 4 ++-- src/qt/qt_main.cpp | 3 ++- src/qt/qt_mainwindow.cpp | 3 +++ src/qt/qt_rendererstack.cpp | 2 ++ src/video/video.c | 13 ++----------- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/86box.c b/src/86box.c index eb8b786be..f01842465 100644 --- a/src/86box.c +++ b/src/86box.c @@ -1321,7 +1321,7 @@ set_screen_size(int x, int y) break; } - atomic_flag_clear(&doresize_monitors[monitor_index_global]); + atomic_store(&doresize_monitors[monitor_index_global], 1); } diff --git a/src/include/86box/video.h b/src/include/86box/video.h index 7a146c743..da3251bb3 100644 --- a/src/include/86box/video.h +++ b/src/include/86box/video.h @@ -24,7 +24,7 @@ #ifdef __cplusplus #include -using atomic_flag = std::atomic_flag; +using atomic_bool = std::atomic_bool; #else #include #endif @@ -132,7 +132,7 @@ typedef struct monitor_settings_t { #define MONITORS_NUM 8 extern monitor_t monitors[MONITORS_NUM]; extern monitor_settings_t monitor_settings[MONITORS_NUM]; -extern atomic_flag doresize_monitors[MONITORS_NUM]; +extern atomic_bool doresize_monitors[MONITORS_NUM]; extern int monitor_index_global; extern int herc_enabled; diff --git a/src/qt/qt_main.cpp b/src/qt/qt_main.cpp index b9bf1c3de..f8469927e 100644 --- a/src/qt/qt_main.cpp +++ b/src/qt/qt_main.cpp @@ -291,11 +291,12 @@ int main(int argc, char* argv[]) { /* If needed, handle a screen resize. */ for (int i = 0; i < MONITORS_NUM; i++) { if (!monitors[i].target_buffer) continue; - if (!atomic_flag_test_and_set(&doresize_monitors[i]) && !video_fullscreen && !is_quit) { + if (atomic_load(&doresize_monitors[i]) == 1 && !video_fullscreen && !is_quit) { if (vid_resize & 2) plat_resize_monitor(fixed_size_x, fixed_size_y, i); else plat_resize_monitor(monitors[i].mon_scrnsz_x, monitors[i].mon_scrnsz_y, i); + atomic_store(&doresize_monitors[i], 0); } } diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index a894eb9a4..cc0eb9bf2 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -1875,6 +1875,9 @@ void MainWindow::on_actionHiDPI_scaling_triggered() dpi_scale ^= 1; ui->actionHiDPI_scaling->setChecked(dpi_scale); emit resizeContents(monitors[0].mon_scrnsz_x, monitors[0].mon_scrnsz_y); + for (int i = 1; i < MONITORS_NUM; i++) { + if (renderers[i]) emit resizeContentsMonitor(monitors[i].mon_scrnsz_x, monitors[i].mon_scrnsz_y, i); + } } void MainWindow::on_actionHide_status_bar_triggered() diff --git a/src/qt/qt_rendererstack.cpp b/src/qt/qt_rendererstack.cpp index 1d5a3cd3d..36d76c1ed 100644 --- a/src/qt/qt_rendererstack.cpp +++ b/src/qt/qt_rendererstack.cpp @@ -44,6 +44,7 @@ #endif extern "C" { +#include <86box/86box.h> #include <86box/mouse.h> #include <86box/plat.h> #include <86box/video.h> @@ -446,6 +447,7 @@ RendererStack::blitCommon(int x, int y, int w, int h) void RendererStack::closeEvent(QCloseEvent* event) { + if (cpu_thread_run == 0 || is_quit == 0) { event->accept(); return; } event->ignore(); main_window->close(); } diff --git a/src/video/video.c b/src/video/video.c index 993293d78..b01e00058 100644 --- a/src/video/video.c +++ b/src/video/video.c @@ -103,17 +103,7 @@ static uint32_t cga_2_table[16]; static uint8_t thread_run = 0; monitor_t monitors[MONITORS_NUM]; monitor_settings_t monitor_settings[MONITORS_NUM]; -atomic_flag doresize_monitors[MONITORS_NUM] = -{ - [0] = ATOMIC_FLAG_INIT, - [1] = ATOMIC_FLAG_INIT, - [2] = ATOMIC_FLAG_INIT, - [3] = ATOMIC_FLAG_INIT, - [4] = ATOMIC_FLAG_INIT, - [5] = ATOMIC_FLAG_INIT, - [6] = ATOMIC_FLAG_INIT, - [7] = ATOMIC_FLAG_INIT -}; +atomic_bool doresize_monitors[MONITORS_NUM]; int monitor_index_global = 0; int herc_enabled = 0; @@ -945,6 +935,7 @@ video_monitor_init(int index) monitors[index].mon_cga_palette = calloc(1, sizeof(int)); monitors[index].mon_force_resize = 1; monitors[index].mon_vid_type = VIDEO_FLAG_TYPE_NONE; + atomic_init(&doresize_monitors[index], 0); if (index >= 1) ui_init_monitor(index); monitors[index].mon_blit_data_ptr->blit_thread = thread_create(blit_thread, monitors[index].mon_blit_data_ptr); }